Documentation
¶
Overview ¶
Package network provides centralized HTTP client management with proxy support. It allows runtime proxy configuration updates that propagate to all HTTP clients.
Index ¶
- Variables
- type ClientPurpose
- type GlobalProxyConfig
- type GlobalProxyType
- type HTTPClientFactory
- func (f *HTTPClientFactory) GetFasthttpClient(purpose ClientPurpose) *fasthttp.Client
- func (f *HTTPClientFactory) GetHTTPClient(purpose ClientPurpose) *http.Client
- func (f *HTTPClientFactory) GetProxyConfig() *GlobalProxyConfig
- func (f *HTTPClientFactory) UpdateProxyConfig(config *GlobalProxyConfig)
Constants ¶
This section is empty.
Variables ¶
var DefaultClientConfig = struct { ReadTimeout time.Duration WriteTimeout time.Duration MaxIdleConnDuration time.Duration MaxConnsPerHost int }{ ReadTimeout: 60 * time.Second, WriteTimeout: 60 * time.Second, MaxIdleConnDuration: 120 * time.Second, MaxConnsPerHost: 200, }
DefaultClientConfig holds default timeout values for HTTP clients
Functions ¶
This section is empty.
Types ¶
type ClientPurpose ¶
type ClientPurpose string
ClientPurpose defines the intended use of an HTTP client for proxy filtering
const ( // ClientPurposeSCIM is used for SCIM/OAuth provider requests ClientPurposeSCIM ClientPurpose = "scim" // ClientPurposeInference is used for LLM inference requests ClientPurposeInference ClientPurpose = "inference" // ClientPurposeAPI is used for general API requests (guardrails, etc.) ClientPurposeAPI ClientPurpose = "api" )
type GlobalProxyConfig ¶
type GlobalProxyConfig struct {
Enabled bool `json:"enabled"`
Type GlobalProxyType `json:"type"` // "http", "socks5", "tcp"
URL string `json:"url"` // Proxy URL (e.g., http://proxy.example.com:8080)
Username string `json:"username,omitempty"` // Optional authentication username
Password string `json:"password,omitempty"` // Optional authentication password
NoProxy string `json:"no_proxy,omitempty"` // Comma-separated list of hosts to bypass proxy
Timeout int `json:"timeout,omitempty"` // Connection timeout in seconds
SkipTLSVerify bool `json:"skip_tls_verify,omitempty"` // Skip TLS certificate verification
// Entity enablement flags
EnableForSCIM bool `json:"enable_for_scim"` // Enable proxy for SCIM requests (enterprise only)
EnableForInference bool `json:"enable_for_inference"` // Enable proxy for inference requests
EnableForAPI bool `json:"enable_for_api"` // Enable proxy for API requests
}
GlobalProxyConfig represents the global proxy configuration
type GlobalProxyType ¶
type GlobalProxyType string
GlobalProxyType represents the type of global proxy
const ( GlobalProxyTypeHTTP GlobalProxyType = "http" GlobalProxyTypeSOCKS5 GlobalProxyType = "socks5" GlobalProxyTypeTCP GlobalProxyType = "tcp" )
type HTTPClientFactory ¶
type HTTPClientFactory struct {
// contains filtered or unexported fields
}
HTTPClientFactory manages HTTP clients with centralized proxy configuration. It supports both fasthttp and standard net/http clients with purpose-based proxy enablement (SCIM, Inference, API).
func NewHTTPClientFactory ¶
func NewHTTPClientFactory(proxyConfig *GlobalProxyConfig, logger schemas.Logger) *HTTPClientFactory
NewHTTPClientFactory creates a new HTTP client factory with the given proxy configuration. Pass nil for proxyConfig if proxy is not yet configured.
func (*HTTPClientFactory) GetFasthttpClient ¶
func (f *HTTPClientFactory) GetFasthttpClient(purpose ClientPurpose) *fasthttp.Client
GetFasthttpClient returns a fasthttp client configured for the given purpose. If proxy is enabled for this purpose, the client will be configured with proxy settings. Clients are cached and reused until proxy config changes.
func (*HTTPClientFactory) GetHTTPClient ¶
func (f *HTTPClientFactory) GetHTTPClient(purpose ClientPurpose) *http.Client
GetHTTPClient returns a standard net/http client configured for the given purpose. If proxy is enabled for this purpose, the client will be configured with proxy settings. Clients are cached and reused until proxy config changes.
func (*HTTPClientFactory) GetProxyConfig ¶
func (f *HTTPClientFactory) GetProxyConfig() *GlobalProxyConfig
GetProxyConfig returns the current proxy configuration (thread-safe read)
func (*HTTPClientFactory) UpdateProxyConfig ¶
func (f *HTTPClientFactory) UpdateProxyConfig(config *GlobalProxyConfig)
UpdateProxyConfig updates the proxy configuration and recreates all cached clients. This is thread-safe and can be called at runtime.