Documentation
¶
Overview ¶
Package fetch performs bounded HTTP transfers using caller-owned requests and clients.
Open checks response status and redirect safety and enforces the supplied body size limit. The request context controls cancellation. Callers close the body and own content validation, hashing, storage, and cache policy.
Index ¶
- Constants
- Variables
- func Ask(ctx context.Context, client *http.Client, url string) bool
- func Open(client *http.Client, request *http.Request, limit int64) (*http.Response, error)
- func OpenFTP(ctx context.Context, address string, limit int64) (io.ReadCloser, error)
- func Scheme(scheme string) bool
- type Stall
- type StatusError
Constants ¶
const BodyStall = 3 * time.Minute
BodyStall is how long a response's body may go without a byte before it's given up, as long as a download may (Stall).
const ResponseWait = time.Minute
ResponseWait is how long a request waits for a response's headers once it's sent.
const UserAgent = "dockhand/2"
Open requires a successful HTTP response and bounds bytes read from its body. The caller closes the body and decides content validation, hashing, and storage. UserAgent identifies dockhand's own HTTP requests. Some listings, MetaCPAN among them, refuse a client library's default agent.
Variables ¶
var Client = &http.Client{Transport: Transport}
Client is the HTTP client dockhand's requests go through, on Transport.
var DownloadClient = &http.Client{Transport: downloadTransport()}
DownloadClient is Client for a download, which a Stall bounds, the wait for its response included: Transport's minute would cut that wait short of a download's own bound.
var ErrStalled = errors.New("fetch: no data arrived")
ErrStalled means a transfer went longer than its bound without a byte.
var ErrTooLarge = errors.New("fetch: response exceeds size limit")
ErrTooLarge reports a body that exceeds the caller's size limit, whether the server declared the size or the limit was reached while reading.
var Transport http.RoundTripper = &stalling{next: newTransport(), bound: BodyStall}
Transport is how dockhand's requests reach a host: Go's default, which bounds connecting at 30 s and a TLS handshake at 10 s, and a response's headers at ResponseWait, which it doesn't. A host that accepted a request and never answered held outdated, and serve's daily look, as long as the command ran (the limits sweep, 2026-10-01). A body that stops after its headers is given up once BodyStall passes without a byte: GitHub's API, a job's log, PyPI, and the mirror's index were held by one as long as the command ran (batch 26).
Functions ¶
func Ask ¶
Ask reports whether a URL answers, below 400: it asks for its head, and, where that isn't answered, as some servers refuse HEAD, its first byte, following redirects as Open does: one from HTTPS to plain HTTP is no answer. Unlike Open's, its success is any status below 400, since a probe needs no body.
Types ¶
type Stall ¶
type Stall struct {
// contains filtered or unexported fields
}
Stall bounds a transfer by its silences rather than its length. A download's size is unbounded, at the person's word (2026-10-01), and a bound on its whole time would bound its size as surely: rustc's 566 MB source passed the two minutes it had. A transfer going on at any pace goes on; one that stops is given up.
func NewStall ¶
NewStall gives a context that's cancelled, with ErrStalled as its cause, once bound passes with no byte read through the stall's Reader, the wait for a response included; Stop ends it.
type StatusError ¶
type StatusError struct {
Status int
URL string
Requested string `json:",omitempty"`
Reason string `json:",omitempty"`
}
StatusError reports an unsuccessful response with the URL that produced it. Requested is the URL asked for when a redirect led somewhere else, and Reason is the first line of a plain-text or JSON body, which is where a server usually says why it refused.
func (*StatusError) Error ¶
func (e *StatusError) Error() string