Documentation
¶
Overview ¶
Package httpclient provides a centralized HTTP client factory with unified configuration.
Index ¶
- Constants
- func NewDefaultHTTPClient() *http.Client
- func NewHTTPClient(config *ClientConfig) *http.Client
- func ParseProxyURL(raw string) (*url.URL, error)
- func RedactProxyURL(raw string) string
- func SetConfiguredStreamIdleTimeout(seconds int)
- func SetConfiguredTimeouts(timeoutSeconds, responseHeaderTimeoutSeconds int)
- func StreamIdleTimeout() time.Duration
- type ClientConfig
Constants ¶
const DefaultStreamIdleTimeout = 300 * time.Second
DefaultStreamIdleTimeout is how long an upstream stream may stay silent, once its first bytes arrived, before it is treated as stalled. Healthy streams send tokens or keep-alive events far more often than this.
Variables ¶
This section is empty.
Functions ¶
func NewDefaultHTTPClient ¶
NewDefaultHTTPClient creates a new HTTP client with default configuration. This is a convenience function equivalent to NewHTTPClient(nil).
func NewHTTPClient ¶
func NewHTTPClient(config *ClientConfig) *http.Client
NewHTTPClient creates a new HTTP client with the provided configuration. If config is nil, DefaultConfig() is used.
func ParseProxyURL ¶ added in v0.1.96
ParseProxyURL validates an outbound proxy URL such as "http://proxy.internal:3128" or "socks5://user:pass@10.0.0.1:1080". The error message never echoes the URL, which may carry credentials.
func RedactProxyURL ¶ added in v0.1.96
RedactProxyURL returns a valid proxy URL with any password replaced by "xxxxx", for logs and admin views, and a fixed mask for anything else.
func SetConfiguredStreamIdleTimeout ¶ added in v0.1.93
func SetConfiguredStreamIdleTimeout(seconds int)
SetConfiguredStreamIdleTimeout installs the config-file (`http:` block) stream idle timeout in seconds; 0 disables it. App startup calls this once before providers are constructed. HTTP_STREAM_IDLE_TIMEOUT still takes precedence.
func SetConfiguredTimeouts ¶
func SetConfiguredTimeouts(timeoutSeconds, responseHeaderTimeoutSeconds int)
SetConfiguredTimeouts installs the config-file (`http:` block) timeout defaults, in seconds. App startup calls this once before providers are constructed. The HTTP_TIMEOUT / HTTP_RESPONSE_HEADER_TIMEOUT env vars still take precedence, matching the project-wide env-over-YAML convention. Non-positive values clear the configured default.
func StreamIdleTimeout ¶ added in v0.1.93
StreamIdleTimeout resolves the stream idle timeout, highest precedence first: the HTTP_STREAM_IDLE_TIMEOUT env var (seconds or Go duration), the config-file value, then DefaultStreamIdleTimeout. Zero means disabled.
Types ¶
type ClientConfig ¶
type ClientConfig struct {
// MaxIdleConns controls the maximum number of idle (keep-alive) connections across all hosts
MaxIdleConns int
// MaxIdleConnsPerHost controls the maximum idle (keep-alive) connections to keep per-host
MaxIdleConnsPerHost int
// IdleConnTimeout is the maximum amount of time an idle (keep-alive) connection will remain idle before closing itself
IdleConnTimeout time.Duration
// Timeout specifies a time limit for requests made by the client
Timeout time.Duration
// DialTimeout is the maximum amount of time a dial will wait for a connect to complete
DialTimeout time.Duration
// KeepAlive specifies the interval between keep-alive probes for an active network connection
KeepAlive time.Duration
// TLSHandshakeTimeout specifies the maximum amount of time to wait for a TLS handshake
TLSHandshakeTimeout time.Duration
// ResponseHeaderTimeout specifies the amount of time to wait for a server's response headers
ResponseHeaderTimeout time.Duration
// Proxy selects the outbound proxy for each request. Nil keeps the
// process-wide HTTP_PROXY / HTTPS_PROXY / NO_PROXY behaviour; a function
// returning nil sends that request directly.
Proxy func(*http.Request) (*url.URL, error)
}
ClientConfig holds configuration options for creating HTTP clients
func DefaultConfig ¶
func DefaultConfig() ClientConfig
DefaultConfig returns a ClientConfig with sensible defaults for API clients. Timeout values match OpenAI/Anthropic SDK defaults (10 minutes). Precedence for the two request timeouts, highest first:
- HTTP_TIMEOUT / HTTP_RESPONSE_HEADER_TIMEOUT env vars (seconds, or Go duration format)
- the config-file `http:` block installed via SetConfiguredTimeouts
- the built-in 600s default