commonhttp

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2026 License: GPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultResponsePreviewBytes int64 = 64 * 1024

DefaultResponsePreviewBytes bounds tracker response bodies used for failure artifacts and error text.

Variables

This section is empty.

Functions

func ApplyCookies

func ApplyCookies(req *http.Request, cookies []*http.Cookie)

ApplyCookies adds non-empty cookies to req and ignores nil cookies or blank names and values.

func BuildMultipartPayload

func BuildMultipartPayload(fields map[string]string, files []FileField) ([]byte, string, error)

BuildMultipartPayload encodes single-value fields and files as multipart form data and returns the payload with its Content-Type header value.

func BuildMultipartPayloadMulti

func BuildMultipartPayloadMulti(fields map[string][]string, files []FileField) ([]byte, string, error)

BuildMultipartPayloadMulti encodes repeated field values and files as multipart form data and returns the payload with its Content-Type header value.

func CookiePathCandidates

func CookiePathCandidates(dbPath string, name string, exts ...string) []string

CookiePathCandidates returns cleaned legacy cookie file paths beside dbPath for the supplied tracker name and extensions.

func ExtractHTTPErrorDetail

func ExtractHTTPErrorDetail(body []byte) string

ExtractHTTPErrorDetail returns a compact, redacted error detail from plain text, HTML, or JSON response bodies.

func FileBytes

func FileBytes(path string) ([]byte, error)

FileBytes reads the entire file at path and wraps open/read failures with the trimmed path.

func LoadCookiesForTracker

func LoadCookiesForTracker(ctx context.Context, dbPath string, trackerID string, cookieStore CookieStore, encryptionKey []byte) (map[string]string, error)

LoadCookiesForTracker loads cookies for a tracker from startup cookie files and the database. When both sources are available, database cookies win on conflicts while preserving legacy-file-only cookies. Callers must pass an explicit request-scoped context so cancellation and deadlines are preserved through database cookie reads.

func LoadJSONCookieMap

func LoadJSONCookieMap(path string) (map[string]string, error)

LoadJSONCookieMap reads a JSON cookie map from path and returns non-empty trimmed names with non-empty values.

func LoadNetscapeCookies

func LoadNetscapeCookies(path string, expectedDomain string) ([]*http.Cookie, error)

LoadNetscapeCookies reads Netscape-format cookies from path, optionally filtering by expectedDomain. It trims names and domains, preserves cookie values after the value column, and returns an error when no valid cookies match.

func ReadFirstMatching

func ReadFirstMatching(dir string, patterns ...string) ([]byte, string, error)

ReadFirstMatching returns the first readable non-directory file matched by the supplied glob patterns.

func ReadOptionalFile

func ReadOptionalFile(path string) string

ReadOptionalFile returns file contents for a non-empty path or an empty string when the path is blank or unreadable.

func ReadUploadResponseBody added in v0.2.2

func ReadUploadResponseBody(resp *http.Response, successCandidate bool, previewLimit int64) ([]byte, []byte, error)

ReadUploadResponseBody reads a full success-candidate response for parsers and always returns a bounded preview for diagnostics. Non-success responses are read only up to previewLimit.

func RedactErrorDetail

func RedactErrorDetail(value string) string

RedactErrorDetail trims value after applying the repository secret redactor.

func ResponseBodyPreview added in v0.2.2

func ResponseBodyPreview(body []byte, previewLimit int64) []byte

ResponseBodyPreview returns body unchanged when it fits the limit, otherwise it returns the prefix used for shareable diagnostics.

func WriteFailureArtifact

func WriteFailureArtifact(meta api.PreparedMetadata, dbPath string, tracker string, name string, body []byte, ext string) (string, error)

WriteFailureArtifact stores a tracker failure response under the release temp directory and returns the written path. It returns an empty path when dbPath or the source path is unavailable.

Types

type CookieStore

type CookieStore interface {
	GetAllTrackerCookies(ctx context.Context, trackerID string, key []byte) (map[string]string, error)
}

CookieStore interface for dependency injection of cookie storage (database or file-based). This allows tests and different implementations to be plugged in.

type FileField

type FileField struct {
	FieldName   string
	FileName    string
	Path        string
	ContentType string
	Content     []byte
}

FileField describes one file part in a tracker multipart upload. FieldName is the form field; Content is used when present; otherwise Path is read from disk and FileName overrides the filename sent in the part. ContentType is carried for callers that need to retain media-type metadata, but the current builders use Go's default multipart file-part headers.

type HTTPError

type HTTPError struct {
	// contains filtered or unexported fields
}

HTTPError is a formatted tracker upload failure with redacted response detail.

func UploadHTTPError

func UploadHTTPError(tracker string, status int, body []byte) HTTPError

UploadHTTPError formats a tracker upload HTTP failure with redacted response detail extracted from body.

func UploadHTTPErrorWithURL

func UploadHTTPErrorWithURL(tracker string, status int, url string, body []byte) HTTPError

UploadHTTPErrorWithURL formats a tracker upload HTTP failure with the redacted final URL and response detail.

func (HTTPError) Error

func (e HTTPError) Error() string

Error returns the formatted, redacted tracker upload failure message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL