| 1 |
# Vendored from httpx-aiohttp v0.2.0 (BSD-3-Clause), src/httpx_aiohttp/httpx2/client.py. |
| 2 |
# Copyright (c) 2025, Karen Petrosyan. Licence text and provenance: LICENSE and |
| 3 |
# NOTICE.md in this directory. |
| 4 |
# The code below is verbatim; only this header was added, by Anthropic PBC (2026). |
| 5 |
# Do not edit by hand; re-copy from upstream to update. |
| 6 |
from __future__ import annotations |
| 7 |
|
| 8 |
import ssl |
| 9 |
import typing as t |
| 10 |
|
| 11 |
import httpx2 as httpx |
| 12 |
|
| 13 |
SOCKET_OPTION = t.Union[ |
| 14 |
t.Tuple[int, int, int], |
| 15 |
t.Tuple[int, int, t.Union[bytes, bytearray]], |
| 16 |
t.Tuple[int, int, None, int], |
| 17 |
] |
| 18 |
|
| 19 |
|
| 20 |
class Httpx2AiohttpClient(httpx.AsyncClient): |
| 21 |
def _init_transport( |
| 22 |
self, |
| 23 |
verify: ssl.SSLContext | str | bool = True, |
| 24 |
cert: t.Union[str, t.Tuple[str, str], t.Tuple[str, str, str], None] = None, |
| 25 |
trust_env: bool = True, |
| 26 |
http1: bool = True, |
| 27 |
http2: bool = False, |
| 28 |
limits: httpx.Limits = httpx.Limits(max_connections=100, max_keepalive_connections=20), |
| 29 |
transport: httpx.AsyncBaseTransport | None = None, |
| 30 |
**kwargs: t.Any, |
| 31 |
) -> httpx.AsyncBaseTransport: |
| 32 |
from .transport import AiohttpTransport |
| 33 |
|
| 34 |
if transport is not None: |
| 35 |
return transport |
| 36 |
|
| 37 |
return AiohttpTransport( |
| 38 |
verify=verify, |
| 39 |
cert=cert, |
| 40 |
trust_env=trust_env, |
| 41 |
http1=http1, |
| 42 |
http2=http2, |
| 43 |
limits=limits, |
| 44 |
) |
| 45 |
|
| 46 |
def _init_proxy_transport( |
| 47 |
self, |
| 48 |
proxy: httpx.Proxy, |
| 49 |
verify: ssl.SSLContext | str | bool = True, |
| 50 |
cert: t.Union[str, t.Tuple[str, str], t.Tuple[str, str, str], None] = None, |
| 51 |
trust_env: bool = True, |
| 52 |
http1: bool = True, |
| 53 |
http2: bool = False, |
| 54 |
limits: httpx.Limits = httpx.Limits(max_connections=100, max_keepalive_connections=20), |
| 55 |
**kwargs: t.Any, |
| 56 |
) -> httpx.AsyncBaseTransport: |
| 57 |
from .transport import AiohttpTransport |
| 58 |
|
| 59 |
return AiohttpTransport( |
| 60 |
verify=verify, |
| 61 |
cert=cert, |
| 62 |
trust_env=trust_env, |
| 63 |
http1=http1, |
| 64 |
http2=http2, |
| 65 |
limits=limits, |
| 66 |
proxy=proxy, |
| 67 |
) |