File size: 843 Bytes
0d10048
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
31
32
33
34
35
36
"""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
    )