ccproxy.http.pool¶
ccproxy.http.pool
¶
HTTP Connection Pool Manager for CCProxy.
This module provides centralized management of HTTP connection pools, ensuring efficient resource usage and preventing duplicate client creation. Implements Phase 2.3 of the refactoring plan.
HTTPPoolManager
¶
Manages HTTP connection pools for different base URLs.
This manager ensures that: - Each unique base URL gets its own optimized connection pool - Connection pools are reused across all components - Resources are properly cleaned up on shutdown - Configuration is consistent across all clients
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
Settings | None
|
Optional application settings for configuration |
None
|
hook_manager
|
Any | None
|
Optional hook manager for request/response tracing |
None
|
Source code in ccproxy/http/pool.py
get_client
async
¶
Get or create an HTTP client for the specified base URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str | None
|
Optional base URL for the client. If None, returns the default client |
None
|
timeout
|
float | None
|
Optional custom timeout for this client |
None
|
headers
|
dict[str, str] | None
|
Optional default headers for this client |
None
|
**kwargs
|
Any
|
Additional configuration for the client |
{}
|
Returns:
| Type | Description |
|---|---|
AsyncClient
|
Configured httpx.AsyncClient instance |
Source code in ccproxy/http/pool.py
get_shared_client
async
¶
Get the default general-purpose HTTP client.
This client is used for requests without a specific base URL and is managed by this pool manager for reuse during the app lifetime.
Returns:
| Type | Description |
|---|---|
AsyncClient
|
The default httpx.AsyncClient instance |
Source code in ccproxy/http/pool.py
get_streaming_client
async
¶
Get or create a client optimized for streaming.
Uses a longer read timeout appropriate for SSE/streaming endpoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str | None
|
Optional base URL for the client |
None
|
headers
|
dict[str, str] | None
|
Optional default headers |
None
|
**kwargs
|
Any
|
Additional client kwargs merged into configuration |
{}
|
Returns:
| Type | Description |
|---|---|
AsyncClient
|
Configured httpx.AsyncClient instance |
Source code in ccproxy/http/pool.py
get_shared_client_sync
¶
Get or create the default client synchronously.
This is used during initialization when we're not in an async context. Note: This doesn't use locking, so it should only be called during single-threaded initialization.
Returns:
| Type | Description |
|---|---|
AsyncClient
|
The default httpx.AsyncClient instance |
Source code in ccproxy/http/pool.py
get_pool_client
¶
Get an existing client for a base URL without creating one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
The base URL to look up |
required |
Returns:
| Type | Description |
|---|---|
AsyncClient | None
|
Existing client or None if not found |
Source code in ccproxy/http/pool.py
close_pool
async
¶
Close and remove a specific connection pool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
The base URL of the pool to close |
required |
Source code in ccproxy/http/pool.py
close_all
async
¶
Close all connection pools and clean up resources.
This should be called during application shutdown.