Spaces:
Running
Running
| """Shared HTTP client factory.""" | |
| import httpx | |
| from typing import Optional, Dict | |
| def create_http_client( | |
| timeout: float = 30.0, | |
| headers: Optional[Dict[str, str]] = None, | |
| follow_redirects: bool = True | |
| ) -> httpx.AsyncClient: | |
| """ | |
| Create a configured async HTTP client. | |
| Args: | |
| timeout: Request timeout in seconds | |
| headers: Default headers to include | |
| follow_redirects: Whether to follow redirects | |
| Returns: | |
| Configured httpx.AsyncClient | |
| """ | |
| default_headers = { | |
| "Accept": "application/json", | |
| "Content-Type": "application/json", | |
| } | |
| if headers: | |
| default_headers.update(headers) | |
| return httpx.AsyncClient( | |
| timeout=timeout, | |
| headers=default_headers, | |
| follow_redirects=follow_redirects | |
| ) | |