diff --git a/CHANGELOG.md b/CHANGELOG.md index d19b2ab8df..4942c9c9a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Unreleased +### Added + +* Add `socket_options` argument to `httpx.HTTPTransport` and `httpx.AsyncHTTPTransport` classes. (#2716) + ### Fixed * Return `500` error response instead of exceptions when `raise_app_exceptions=False` is set on `ASGITransport`. (#2669) diff --git a/httpx/_transports/default.py b/httpx/_transports/default.py index fca7de98d9..1aebd5c5a5 100644 --- a/httpx/_transports/default.py +++ b/httpx/_transports/default.py @@ -53,6 +53,12 @@ T = typing.TypeVar("T", bound="HTTPTransport") A = typing.TypeVar("A", bound="AsyncHTTPTransport") +SOCKET_OPTION = typing.Union[ + typing.Tuple[int, int, int], + typing.Tuple[int, int, typing.Union[bytes, bytearray]], + typing.Tuple[int, int, None, int], +] + @contextlib.contextmanager def map_httpcore_exceptions() -> typing.Iterator[None]: @@ -122,6 +128,7 @@ def __init__( uds: typing.Optional[str] = None, local_address: typing.Optional[str] = None, retries: int = 0, + socket_options: typing.Optional[typing.Iterable[SOCKET_OPTION]] = None, ) -> None: ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env) @@ -136,6 +143,7 @@ def __init__( uds=uds, local_address=local_address, retries=retries, + socket_options=socket_options, ) elif proxy.url.scheme in ("http", "https"): self._pool = httpcore.HTTPProxy( @@ -153,6 +161,7 @@ def __init__( keepalive_expiry=limits.keepalive_expiry, http1=http1, http2=http2, + socket_options=socket_options, ) elif proxy.url.scheme == "socks5": try: @@ -257,6 +266,7 @@ def __init__( uds: typing.Optional[str] = None, local_address: typing.Optional[str] = None, retries: int = 0, + socket_options: typing.Optional[typing.Iterable[SOCKET_OPTION]] = None, ) -> None: ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env) @@ -271,6 +281,7 @@ def __init__( uds=uds, local_address=local_address, retries=retries, + socket_options=socket_options, ) elif proxy.url.scheme in ("http", "https"): self._pool = httpcore.AsyncHTTPProxy( @@ -288,6 +299,7 @@ def __init__( keepalive_expiry=limits.keepalive_expiry, http1=http1, http2=http2, + socket_options=socket_options, ) elif proxy.url.scheme == "socks5": try: diff --git a/pyproject.toml b/pyproject.toml index d5313c64cf..30228c120e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ classifiers = [ ] dependencies = [ "certifi", - "httpcore>=0.15.0,<0.18.0", + "httpcore>=0.17.2,<0.18.0", "idna", "sniffio", ]