httpx

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 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 httpx provides PlugIt's hardened HTTP client (SPEC §5.3: T8, T9, T12). Every outbound request PlugIt makes goes through it.

  • SSRF guard: the IP actually being connected is checked at dial time (net.Dialer.Control), so DNS rebinding cannot slip past a hostname check. Private ranges are blocked unless AllowPrivate is set; cloud metadata, unspecified, multicast and reserved addresses are always blocked.
  • Redirects are followed only within the same origin, at most MaxRedirects times.
  • Response bodies are capped at MaxResponseBytes (after decompression). Reading past the cap returns the capped bytes followed by ErrResponseTruncated instead of io.EOF.
  • A total timeout covers dial, headers and body.
  • Proxy environment variables are ignored: dialing a proxy would check the proxy's address instead of the target's.

Index

Constants

View Source
const (
	DefaultTimeout          = 30 * time.Second
	DefaultMaxResponseBytes = 1 << 20
	DefaultMaxRedirects     = 5
)

Defaults applied when the corresponding Options field is zero.

Variables

View Source
var (
	ErrBlockedAddress    = errors.New("blocked address")
	ErrRedirectBlocked   = errors.New("cross-origin redirect blocked")
	ErrTooManyRedirects  = errors.New("too many redirects")
	ErrResponseTruncated = errors.New("response truncated at size cap")
)

Sentinel errors callers can match with errors.Is.

Functions

func NewClient

func NewClient(opts Options) *http.Client

NewClient returns a hardened *http.Client configured by opts.

func Origin

func Origin(u *url.URL) string

Origin returns u's origin as scheme://host:port, lowercased, with the scheme's default port filled in. It returns "" when u has no host.

func SameOrigin

func SameOrigin(a, b *url.URL) bool

SameOrigin reports whether a and b have exactly the same scheme, host and port. Credentials are attached only when this holds against the pinned base_url (SPEC §5.3, T8).

Types

type Doer

type Doer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer sends an HTTP request. *http.Client implements it; tests inject fakes.

type Options

type Options struct {
	AllowPrivate     bool
	Timeout          time.Duration
	MaxResponseBytes int64
	MaxRedirects     int
	Resolver         Resolver
}

Options configures NewClient. The zero value is the secure default.

type Resolver

type Resolver interface {
	LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error)
}

Resolver looks up the addresses of a host. *net.Resolver implements it.

Jump to

Keyboard shortcuts

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