From 2f737cadc1815245c49fbf00f25e14a50f7c46e7 Mon Sep 17 00:00:00 2001 From: Kar Petrosyan Date: Tue, 10 Jun 2025 23:03:04 +0400 Subject: [PATCH 1/2] feat: add socket_options to Client and AsyncClient classes --- httpx/_client.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/httpx/_client.py b/httpx/_client.py index 13cd933673..c95ce147e0 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -29,7 +29,7 @@ from ._models import Cookies, Headers, Request, Response from ._status_codes import codes from ._transports.base import AsyncBaseTransport, BaseTransport -from ._transports.default import AsyncHTTPTransport, HTTPTransport +from ._transports.default import SOCKET_OPTION, AsyncHTTPTransport, HTTPTransport from ._types import ( AsyncByteStream, AuthTypes, @@ -653,6 +653,7 @@ def __init__( timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG, follow_redirects: bool = False, limits: Limits = DEFAULT_LIMITS, + socket_options: typing.Iterable[SOCKET_OPTION] | None = None, max_redirects: int = DEFAULT_MAX_REDIRECTS, event_hooks: None | (typing.Mapping[str, list[EventHook]]) = None, base_url: URL | str = "", @@ -693,6 +694,7 @@ def __init__( http2=http2, limits=limits, transport=transport, + socket_options=socket_options, ) self._mounts: dict[URLPattern, BaseTransport | None] = { URLPattern(key): None @@ -705,6 +707,7 @@ def __init__( http1=http1, http2=http2, limits=limits, + socket_options=socket_options, ) for key, proxy in proxy_map.items() } @@ -723,6 +726,7 @@ def _init_transport( http1: bool = True, http2: bool = False, limits: Limits = DEFAULT_LIMITS, + socket_options: typing.Iterable[SOCKET_OPTION] | None = None, transport: BaseTransport | None = None, ) -> BaseTransport: if transport is not None: @@ -735,6 +739,7 @@ def _init_transport( http1=http1, http2=http2, limits=limits, + socket_options=socket_options, ) def _init_proxy_transport( @@ -746,6 +751,7 @@ def _init_proxy_transport( http1: bool = True, http2: bool = False, limits: Limits = DEFAULT_LIMITS, + socket_options: typing.Iterable[SOCKET_OPTION] | None = None, ) -> BaseTransport: return HTTPTransport( verify=verify, @@ -755,6 +761,7 @@ def _init_proxy_transport( http2=http2, limits=limits, proxy=proxy, + socket_options=socket_options, ) def _transport_for_url(self, url: URL) -> BaseTransport: @@ -1366,6 +1373,7 @@ def __init__( timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG, follow_redirects: bool = False, limits: Limits = DEFAULT_LIMITS, + socket_options: typing.Iterable[SOCKET_OPTION] | None = None, max_redirects: int = DEFAULT_MAX_REDIRECTS, event_hooks: None | (typing.Mapping[str, list[EventHook]]) = None, base_url: URL | str = "", @@ -1407,6 +1415,7 @@ def __init__( http2=http2, limits=limits, transport=transport, + socket_options=socket_options, ) self._mounts: dict[URLPattern, AsyncBaseTransport | None] = { @@ -1420,6 +1429,7 @@ def __init__( http1=http1, http2=http2, limits=limits, + socket_options=socket_options, ) for key, proxy in proxy_map.items() } @@ -1437,6 +1447,7 @@ def _init_transport( http1: bool = True, http2: bool = False, limits: Limits = DEFAULT_LIMITS, + socket_options: typing.Iterable[SOCKET_OPTION] | None = None, transport: AsyncBaseTransport | None = None, ) -> AsyncBaseTransport: if transport is not None: @@ -1449,6 +1460,7 @@ def _init_transport( http1=http1, http2=http2, limits=limits, + socket_options=socket_options, ) def _init_proxy_transport( @@ -1460,6 +1472,7 @@ def _init_proxy_transport( http1: bool = True, http2: bool = False, limits: Limits = DEFAULT_LIMITS, + socket_options: typing.Iterable[SOCKET_OPTION] | None = None, ) -> AsyncBaseTransport: return AsyncHTTPTransport( verify=verify, @@ -1469,6 +1482,7 @@ def _init_proxy_transport( http2=http2, limits=limits, proxy=proxy, + socket_options=socket_options, ) def _transport_for_url(self, url: URL) -> AsyncBaseTransport: From f88fa846d9eb82fa55acc1965459a4a488c5938a Mon Sep 17 00:00:00 2001 From: Kar Petrosyan Date: Tue, 10 Jun 2025 23:13:35 +0400 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee0f81f9c3..727b848e8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## Development + +* Add `socket_options` to `Client` and `AsyncClient` classes. (#3587) + ## 0.28.1 (6th December, 2024) * Fix SSL case where `verify=False` together with client side certificates.