Documentation
¶
Overview ¶
Package httpfetch is a minimal HTTP client wrapper that exposes a streaming Get plus an atomic Download (temp file in dest dir + rename). It's the shared transport for stepman's V2 inventory fetches and precompiled binary downloads.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
// Get streams the body of url. The caller closes the returned reader.
// Non-2xx responses are returned as an error.
Get(ctx context.Context, url string) (io.ReadCloser, error)
// Download fetches url and atomically writes it to destPath. Missing
// parent directories are created. A temp file is created alongside
// destPath and renamed on success so partial downloads never appear at
// the final path.
Download(ctx context.Context, destPath, url string) error
// DownloadWithHash behaves like Download but also verifies that the
// downloaded content matches expectedHash ("sha256-<hex>"). The temp file
// is removed and an error is returned if the hash does not match, so a
// mismatched file never appears at destPath.
DownloadWithHash(ctx context.Context, destPath, url, expectedHash string) error
}
Client streams or atomically downloads HTTP resources. Implementations returned by NewClient retry transient failures on both Get and Download.
func NewClient ¶
NewClient returns a Client backed by a retryablehttp client, so callers get transient-failure retries by default. Use NewWithClient to supply a specific *http.Client (e.g. a test server's client).
func NewWithClient ¶
NewWithClient returns a Client backed by the given httpClient, which must be non-nil. Prefer NewClient unless you need a specific transport.
type Logger ¶
Logger is the minimal logging interface Client needs; the retry adapter only emits debug lines.
type StatusError ¶
StatusError is returned by Get when the server responds with a non-2xx status, so callers can branch on the code (e.g. treat 404 as "not found") via errors.As. Body holds a bounded snippet of the response body, which usually explains the failure (a 404 page, S3's XML error, …).
func (*StatusError) Error ¶
func (e *StatusError) Error() string