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's SHA256 digest, hex-encoded, matches expectedHash.
// The temp file is removed and an error is returned if the digest 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 NewCachingWithClient ¶ added in v0.27.0
NewCachingWithClient returns a caching Client. Prefer NewCachingClient unless you need a specific transport.
func NewWithClient ¶
NewWithClient returns a Client backed by the given httpClient. Prefer NewClient unless you need a specific transport.
type Clients ¶ added in v0.27.0
type Clients struct {
// Caching reads through a HTTP cache that honours Cache-Control and revalidates with ETags.
Caching Client
// Passthrough fetches step archives and precompiled executables, uncached.
Passthrough Client
}
Clients are a pair of caching and passthrough clients. They share one connection pool, for performance.
func NewCachingClient ¶ added in v0.27.0
NewCachingClient returns a caching and a passthrough Client. Both run over the same retrying transport, so they share one connection pool.
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.
func (*StatusError) Error ¶
func (e *StatusError) Error() string