Documentation
¶
Overview ¶
Package httpx sends catalog requests and records the responses exactly: no automatic compression, no connection reuse, no proxies from the environment, and no connection to a host that is not allowed.
Index ¶
Constants ¶
const DefaultUserAgent = "driftgate/1"
DefaultUserAgent is sent unless the configuration sets another. It does not carry the DriftGate version, so captures stay comparable across releases.
const MaxBody = 256 << 20
MaxBody bounds a response body so a runaway endpoint cannot exhaust memory.
Variables ¶
var ErrHostNotAllowed = errors.New("host not allowed")
ErrHostNotAllowed is returned for a connection to a host outside the allow-list.
var LocalHosts = []string{"localhost", "127.0.0.0/8", "::1/128"}
LocalHosts is an allow-list of the local system only.
Functions ¶
func Decode ¶
Decode undoes the Content-Encoding of a body, the last encoding applied first: gzip and deflate (zlib, or raw as some servers send it); identity and no encoding leave it as it is. The decoded body is capped at max, so a small body that expands without end is not read past it. ok is false for an encoding it cannot decode (br, zstd), a body that does not decode, or one over max. The buffer is sized from the size gzip records, so a large body is not grown into twice its size.
func Headers ¶
Headers turns a header map into sorted, lower-case pairs with sensitive values masked. Go does not keep the received order of header names; the comparison ignores that order anyway.
func MaskHeader ¶
MaskHeader hides secrets in header values while keeping their format, so allow-list formats still match: letters become x, digits 0. Besides the headers that carry credentials by definition (Authorization, Cookie, Set-Cookie's value), a header named as a credential (X-CSRF-Token, X-Api-Key, devise_token_auth's Access-Token, Token, Api-Key) is masked, except the standard ones in plainHeaders, and in a header that holds a URL (Location, Content-Location, Link, Refresh) the values of query and fragment parameters named or shaped as credentials (token=, signature=, X-Amz-Signature=, #access_token=) and path segments shaped as one (a reset link's token).
func Unreleased ¶
func Unreleased() int
Unreleased is the number of bodies read off the heap whose results are not released yet: after a capture, 0.
Types ¶
type Allow ¶
type Allow struct {
// LookupIP, when set, resolves names instead of the system resolver
// (tests).
LookupIP func(ctx context.Context, network, host string) ([]net.IP, error)
// contains filtered or unexported fields
}
Allow decides which hosts may be contacted.
func NewAllow ¶
NewAllow builds the allow-list from host names and CIDR ranges. An empty list means local and private addresses; anyHost lifts every restriction.
func (*Allow) Check ¶
Check reports an error unless the host is allowed: named in the list, or every address it resolves to inside an allowed range.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client sends catalog requests.
func (*Client) Do ¶
Do sends a request. Transport failures (refused connection, timeout, host not allowed) are returned as a record with Error set, not as an error.
func (*Client) URL ¶
URL builds the full URL of a request, filling {name} placeholders from params. The path must start with "/", and the URL must keep the scheme and host of the base URL: the identity's token goes with the request. An error names the path as the catalog writes it, never with values filled in (they may come from a private body).
type Options ¶
type Options struct {
BaseURL string
UserAgent string
Timeout time.Duration
FollowRedirects bool
Allow *Allow
// OffHeap reads a body that is not small outside the Go heap
// (readOffHeap); the caller then releases every Result.
OffHeap bool
}
Options configure a client.