File size: 620 Bytes
9513328
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Shared HTTP client with connection pooling.
Use this instead of creating ad-hoc httpx clients.

Usage:
    from app.core.http import http_client
    resp = await http_client.get("https://api.example.com/data")
"""

from __future__ import annotations

import httpx

# Single pooled client — reuse across all requests
http_client = httpx.AsyncClient(
    limits=httpx.Limits(
        max_connections=100,
        max_keepalive_connections=20,
    ),
    timeout=httpx.Timeout(30.0),
    follow_redirects=True,
)


async def close_http_client() -> None:
    """Call on app shutdown."""
    await http_client.aclose()