fetch

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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).

View Source
const ResponseWait = time.Minute

ResponseWait is how long a request waits for a response's headers once it's sent.

View Source
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

Client is the HTTP client dockhand's requests go through, on Transport.

View Source
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.

View Source
var ErrStalled = errors.New("fetch: no data arrived")

ErrStalled means a transfer went longer than its bound without a byte.

View Source
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.

View Source
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

func Ask(ctx context.Context, client *http.Client, url string) bool

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.

func Open

func Open(client *http.Client, request *http.Request, limit int64) (*http.Response, error)

func OpenFTP

func OpenFTP(ctx context.Context, address string, limit int64) (io.ReadCloser, error)

OpenFTP retrieves one file by anonymous FTP and returns its body, bounded like an HTTP one. Credentials in the URL are refused: the ports tree's FTP master sites are public archives, and a secret would otherwise travel in the clear.

func Scheme

func Scheme(scheme string) bool

Scheme reports whether a master site's scheme is one the downloader speaks.

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

func NewStall(ctx context.Context, bound time.Duration) (context.Context, *Stall)

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.

func (*Stall) Reader

func (s *Stall) Reader(r io.Reader) io.Reader

Reader reads through r, each byte that arrives putting the bound off.

func (*Stall) Stop

func (s *Stall) Stop()

Stop ends the bound, and the context it gave.

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

Jump to

Keyboard shortcuts

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