Documentation
¶
Overview ¶
Package httpclient provides a centralized HTTP client factory with unified configuration.
Index ¶
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 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
}
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