httpclient

package
v0.1.99 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 10 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 provides a centralized HTTP client factory with unified configuration.

Index

Constants

View Source
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

func NewDefaultHTTPClient() *http.Client

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

func ParseProxyURL(raw string) (*url.URL, error)

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

func RedactProxyURL(raw string) string

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

func StreamIdleTimeout() time.Duration

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

Jump to

Keyboard shortcuts

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