httpclient

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: AGPL-3.0 Imports: 13 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 httpclient is the shared construction point for outbound HTTP transports and clients outside the platform site-proxy regime.

Two regimes coexist by design:

  • Platform adapter traffic (login/checkin/balance/model calls through platform.DoWithProxy) uses the pooled transport cache in platform/site_proxy.go, whose timeouts are operator-tunable via the PROXY_*_TIMEOUT_SEC env vars.
  • Every other outbound path (proxy executor, channel health probes, admin channel test harness, monitor LDOH proxy, notifications, pricing catalog fetch, OAuth token/session exchange, Codex websocket dial, server healthcheck) builds its transport here so each client carries explicit dial / TLS-handshake / idle bounds and a sized connection pool instead of riding http.DefaultTransport.

Baseline values mirror the axonhub HTTP client baseline: dial 30s, TLS handshake 10s, MaxIdleConns 100, IdleConnTimeout 90s.

Index

Constants

View Source
const (
	DefaultDialTimeout           = 30 * time.Second
	DefaultKeepAlive             = 30 * time.Second
	DefaultTLSHandshakeTimeout   = 10 * time.Second
	DefaultIdleConnTimeout       = 90 * time.Second
	DefaultMaxIdleConns          = 100
	DefaultMaxIdleConnsPerHost   = 20
	DefaultExpectContinueTimeout = 1 * time.Second
)

Baseline defaults shared by every outbound transport built in this package.

View Source
const DefaultRequestCeiling = 90 * time.Second

DefaultRequestCeiling bounds buffered upstream requests and the header wait for streams whose first-byte observation is disabled. It never limits a stream's body lifetime.

Variables

View Source
var ErrResponseHeaderTimeout = errors.New("first byte timeout")

ErrResponseHeaderTimeout preserves the proxy's first-byte timeout identity.

Functions

func DoWithHeaderBudget added in v0.20.0

func DoWithHeaderBudget(req *http.Request, firstByteTimeoutMs int64, do func(*http.Request) (*http.Response, error)) (*http.Response, error)

DoWithHeaderBudget owns the header phase of one dispatch, including redirects. firstByteTimeoutMs is milliseconds; non-positive values use DefaultRequestCeiling. Streaming dispatch must reuse a client with no whole-request or transport header timeout. Buffered callers retain their whole-request ceiling and skip this helper when first-byte observation is disabled.

The timer stops when do returns headers. The derived context remains alive for body reads and is cancelled on error or Body.Close; body-idle limits belong to the relay. Neither the client nor its pooled transport is changed per request.

func ExpandClientHeaderTemplate added in v0.23.0

func ExpandClientHeaderTemplate(value string, client http.Header) (string, bool)

ExpandClientHeaderTemplate expands only explicitly allowed request metadata. Backup validation and live forwarding use the same parser and allowlist. Invalid templates return no partial value.

func NewClient

func NewClient(transport http.RoundTripper, timeout time.Duration, checkRedirect func(*http.Request, []*http.Request) error) *http.Client

NewClient wraps transport with a whole-request timeout and a redirect policy. A zero timeout leaves the total request unbounded (streaming callers); the transport's phase timeouts still apply.

func NewTransport

func NewTransport(opts Options) *http.Transport

NewTransport builds an *http.Transport with explicit phase timeouts and a sized idle pool. Proxy resolution keeps http.ProxyFromEnvironment, the behavior these paths historically inherited from http.DefaultTransport.

func NoProxy added in v0.16.20

func NoProxy(*http.Request) (*url.URL, error)

NoProxy is an Options.Proxy value that disables proxy resolution entirely: HTTP_PROXY/HTTPS_PROXY/NO_PROXY environment variables are ignored and every request dials its target directly. It is equivalent to a nil Transport.Proxy but can be passed explicitly through Options.

func SharedTransport

func SharedTransport() *http.Transport

SharedTransport returns the process-wide baseline transport for outbound clients whose whole-request timeout is at most sharedResponseHeaderTimeout (Codex websocket upgrade, server healthcheck). Callers needing a different header-phase cap must build their own transport via NewTransport instead of mutating this one. SSRF-sensitive surfaces (notifications, SMTP, catalog sources, WebDAV) build their own guarded transports instead.

Types

type Options

type Options struct {
	DialTimeout           time.Duration
	TLSHandshakeTimeout   time.Duration
	ResponseHeaderTimeout time.Duration
	IdleConnTimeout       time.Duration
	MaxIdleConns          int
	MaxIdleConnsPerHost   int
	// Proxy overrides the transport's proxy resolution. Nil keeps
	// http.ProxyFromEnvironment, the behavior these paths historically
	// inherited from http.DefaultTransport. Set NoProxy on paths that must
	// never ride an operator-configured HTTP_PROXY (e.g. OAuth token
	// exchange).
	Proxy func(*http.Request) (*url.URL, error)
	// SiteDialGuard rejects explicitly forbidden URL hosts before proxy
	// selection and wraps DialContext with the shared SSRF site dial guard
	// (internal/ssrf): the dial hostname is resolved exactly once, every answer is
	// checked against the metadata / link-local / multicast / reserved deny
	// set, and the connection is pinned to an already-validated IP — closing
	// the DNS-rebinding window between validation and dial. Loopback, RFC1918
	// and IPv6 ULA stay reachable because Metapi upstreams are commonly
	// operator-hosted on private networks.
	//
	// Set it on transports whose target comes from operator-configured site
	// URLs (proxy data plane, channel health probes). When a proxy is selected,
	// DNS validation/pinning covers the proxy address; origin DNS remains the
	// proxy's responsibility. Explicitly forbidden origins are still rejected.
	SiteDialGuard bool
}

Options configures NewTransport. Zero values select the baseline defaults. ResponseHeaderTimeout 0 leaves the header phase unbounded: use that only where a caller context or the client Timeout already owns the deadline (SSE stream relays, context-driven probes).

Jump to

Keyboard shortcuts

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