ccproxy.http.client¶
ccproxy.http.client
¶
Centralized HTTP client configuration and abstractions for CCProxy.
This module provides: - HTTP client factory with optimized configuration for proxy use cases - Generic HTTP client abstractions for pure forwarding without business logic - Lifecycle managed by the ServiceContainer
HTTPError
¶
HTTPTimeoutError
¶
HTTPConnectionError
¶
HTTPClientFactory
¶
Factory for creating optimized HTTP clients.
Provides centralized configuration for HTTP clients with: - Consistent timeout/retry configuration - Unified connection limits - HTTP/2 multiplexing for non-streaming endpoints - Centralized observability hooks (via HookableHTTPClient)
create_client
staticmethod
¶
create_client(
*,
settings=None,
timeout_connect=5.0,
timeout_read=240.0,
max_keepalive_connections=100,
max_connections=1000,
http2=True,
verify=True,
hook_manager=None,
**kwargs,
)
Create an optimized HTTP client with recommended configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
Settings | None
|
Optional settings object for additional configuration |
None
|
timeout_connect
|
float
|
Connection timeout in seconds |
5.0
|
timeout_read
|
float
|
Read timeout in seconds (long for streaming) |
240.0
|
max_keepalive_connections
|
int
|
Max keep-alive connections for reuse |
100
|
max_connections
|
int
|
Max total concurrent connections |
1000
|
http2
|
bool
|
Enable HTTP/2 multiplexing |
True
|
verify
|
bool | str
|
SSL verification (True/False or path to CA bundle) |
True
|
hook_manager
|
Any | None
|
Optional HookManager for request/response interception |
None
|
**kwargs
|
Any
|
Additional httpx.AsyncClient arguments |
{}
|
Returns:
| Type | Description |
|---|---|
AsyncClient
|
Configured httpx.AsyncClient instance |
Source code in ccproxy/http/client.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
create_shared_client
staticmethod
¶
Create an optimized HTTP client.
Prefer managing lifecycle via ServiceContainer + HTTPPoolManager. Kept for compatibility with existing factory call sites.
Source code in ccproxy/http/client.py
create_short_lived_client
staticmethod
¶
Create a client for short-lived operations like version checks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float
|
Short timeout for quick operations |
15.0
|
**kwargs
|
Any
|
Additional client configuration |
{}
|
Returns:
| Type | Description |
|---|---|
AsyncClient
|
Configured httpx.AsyncClient instance for short operations |
Source code in ccproxy/http/client.py
managed_client
async
staticmethod
¶
Create a managed HTTP client with automatic cleanup.
This context manager ensures proper cleanup of HTTP clients in error cases and provides a clean resource management pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
Settings | None
|
Optional settings for configuration |
None
|
**kwargs
|
Any
|
Additional client configuration |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncGenerator[AsyncClient, None]
|
Configured httpx.AsyncClient instance |
Example
async with HTTPClientFactory.managed_client() as client: response = await client.get("https://api.example.com")
Source code in ccproxy/http/client.py
get_proxy_url
¶
Get proxy URL from environment variables.
Returns:
| Type | Description |
|---|---|
str | None
|
str or None: Proxy URL if any proxy is set |
Source code in ccproxy/http/client.py
get_ssl_context
¶
Get SSL context configuration from environment variables.
Returns:
| Type | Description |
|---|---|
str | bool
|
SSL verification configuration: |
str | bool
|
|
str | bool
|
|
str | bool
|
|