httpx

package
v0.53.3 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 11 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 httpx is the one audited egress client. Every outbound HTTP call goes through New: it has an explicit timeout, caps redirects, refuses an https→http downgrade, strips credential headers once a chain leaves its first host, and refuses to dial a cloud metadata address. ReadBody bounds what a response may put in memory.

Index

Constants

View Source
const DefaultTimeout = 10 * time.Second

DefaultTimeout bounds a whole exchange when New is given no positive timeout.

Variables

View Source
var (
	// ErrForbiddenAddress reports a dial to a cloud metadata address.
	ErrForbiddenAddress = errors.New("egress to a cloud metadata address")
	// ErrTooManyRedirects reports a redirect chain longer than the cap.
	ErrTooManyRedirects = errors.New("too many redirects")
	// ErrInsecureRedirect reports an https→http redirect.
	ErrInsecureRedirect = errors.New("redirect from https to http")
	// ErrBodyTooLarge reports a response body over the caller's limit.
	ErrBodyTooLarge = errors.New("response body too large")
)

Functions

func New

func New(timeout time.Duration, roots *x509.CertPool) *http.Client

New returns the egress client. A timeout ≤ 0 means DefaultTimeout. roots, when not nil, replaces the system pool (a private CA such as the broker's).

The guard sits at dial time, not in CheckRedirect, so it covers the first request, every redirect and a DNS name that resolves to a metadata address. No proxy is configured: a proxy would make the dialed address the proxy's.

func NewStreaming

func NewStreaming(timeout time.Duration, roots *x509.CertPool) *http.Client

NewStreaming returns New's client without the whole-exchange Timeout, for a WebSocket or SSE exchange, whose length no timeout fits; every other invariant of New holds, the header timeout, the redirect cap and the metadata guard.

func ReadBody

func ReadBody(r io.Reader, limit int64) ([]byte, error)

ReadBody reads r to its end, or fails with ErrBodyTooLarge once it passes limit bytes. It never returns a truncated body as if it were whole.

Types

This section is empty.

Jump to

Keyboard shortcuts

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