Documentation
¶
Overview ¶
Package connection manages HTTP connection pooling, TLS configuration, and proxy detection for the httpc library.
Index ¶
- Variables
- func AllowPrivateIPsOverrideFromContext(ctx context.Context) (allow bool, ok bool)
- func ProxyAttemptFromContext(ctx context.Context) (attempt int, ok bool)
- func WithAllowPrivateIPsOverride(ctx context.Context, allow bool) context.Context
- func WithProxyAttempt(ctx context.Context, attempt int) context.Context
- type Config
- type PoolManager
Constants ¶
This section is empty.
Variables ¶
var ErrPoolExhausted = fmt.Errorf("connection pool exhausted")
ErrPoolExhausted is returned when the connection pool has reached its maximum capacity and cannot accept new connections. Callers can detect this condition with errors.Is(err, connection.ErrPoolExhausted).
Functions ¶
func AllowPrivateIPsOverrideFromContext ¶ added in v1.5.2
AllowPrivateIPsOverrideFromContext reports the per-request AllowPrivateIPs override carried on ctx. The ok result is false when no override is present, in which case callers fall back to the client-level policy.
func ProxyAttemptFromContext ¶ added in v1.6.0
ProxyAttemptFromContext reports the retry-attempt index carried on ctx. The ok result is false when no attempt is present (non-retry path or when proxy rotation is not configured), in which case the selector falls back to normal round-robin via Pool.Select.
func WithAllowPrivateIPsOverride ¶ added in v1.5.2
WithAllowPrivateIPsOverride returns a copy of ctx that carries a per-request AllowPrivateIPs override. When present, the dialer and redirect validator use this value in place of the client-level config. It is intended for internal use by the engine to honor the per-request WithAllowPrivateIPs option.
ctx must be non-nil; callers (the engine) always supply the request context.
func WithProxyAttempt ¶ added in v1.6.0
WithProxyAttempt returns a copy of ctx that carries the retry-attempt index. When present, the proxy selector uses Pool.SelectIndex(attempt) instead of the round-robin Pool.Select, ensuring each retry attempt deterministically lands on a different proxy even when redirect-following within a single attempt consumes extra Select calls.
ctx must be non-nil; callers (the engine) always supply the request context.
Types ¶
type Config ¶
type Config struct {
MaxIdleConns int
MaxIdleConnsPerHost int
MaxConnsPerHost int
MaxTotalConns int
DialTimeout time.Duration
KeepAlive time.Duration
TLSHandshakeTimeout time.Duration
ResponseHeaderTimeout time.Duration
IdleConnTimeout time.Duration
ExpectContinueTimeout time.Duration
MaxResponseHeaderBytes int64
TLSConfig *tls.Config
MinTLSVersion uint16
MaxTLSVersion uint16
InsecureSkipVerify bool
EnableHTTP2 bool
ProxyURL string
// System proxy configuration
EnableSystemProxy bool // Automatically detect and use system proxy settings
// Proxy pool configuration. When set, requests are distributed across the
// listed proxies with passive circuit breaking. Lower priority than
// ProxyURL, higher than EnableSystemProxy.
ProxyPool []string
ProxyPoolStrategy proxypool.Strategy
ProxyFailureThreshold int
ProxyCooldown time.Duration
AllowPrivateIPs bool
ExemptNets []*net.IPNet
DisableCompression bool
DisableKeepAlives bool
ForceAttemptHTTP2 bool
CookieJar http.CookieJar
// DNS configuration
EnableDoH bool // Enable DNS-over-HTTPS
DoHCacheTTL time.Duration // DoH cache TTL
// contains filtered or unexported fields
}
Config defines connection pool configuration.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns optimized default configuration.
func (*Config) SetCertPinner ¶ added in v1.4.0
func (c *Config) SetCertPinner(p certPinner)
SetCertPinner sets the certificate pinner for TLS certificate verification.
type PoolManager ¶
type PoolManager struct {
// contains filtered or unexported fields
}
PoolManager provides intelligent connection pool management with monitoring
func NewPoolManager ¶
func NewPoolManager(config *Config) (*PoolManager, error)
NewPoolManager creates a new connection pool manager with the given configuration.
func (*PoolManager) Close ¶
func (pm *PoolManager) Close() error
Close releases the PoolManager's resources, including the DoH resolver and the shared transport. It is safe to call multiple times; subsequent calls are no-ops. Returns any error encountered while closing sub-components.
func (*PoolManager) CloseIdleConnections ¶ added in v1.6.0
func (pm *PoolManager) CloseIdleConnections()
CloseIdleConnections closes all idle connections in the underlying transport. Used by the retry layer to force the transport to re-evaluate transport.Proxy on the next request — without this, HTTP/2 connection reuse through a CONNECT tunnel can bypass Proxy() and reuse the connection from a previous attempt, defeating proxy rotation.
func (*PoolManager) GetMetrics ¶
func (pm *PoolManager) GetMetrics() metrics
GetMetrics returns a snapshot of current connection pool statistics, including active, total, and rejected connection counts and the connection hit rate.
func (*PoolManager) GetTransport ¶
func (pm *PoolManager) GetTransport() *http.Transport
GetTransport returns the shared *http.Transport used for pooled connections.
func (*PoolManager) NextProxyIndex ¶ added in v1.6.0
func (pm *PoolManager) NextProxyIndex() (int, bool)
NextProxyIndex advances the proxy pool's round-robin cursor once and returns the resulting base index. The caller (retry engine) combines this with the attempt number (base + attempt) to deterministically select a different proxy per retry, while still rotating across sequential requests. Returns (0, false) when no proxy pool is configured.