From 1e4d1c960205e620103f5a086d606bb0d68e677f Mon Sep 17 00:00:00 2001 From: karosis88 Date: Mon, 22 May 2023 11:28:45 +0300 Subject: [PATCH] Add `sni_hostname` extension --- httpcore/_async/connection.py | 4 +++- httpcore/_sync/connection.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/httpcore/_async/connection.py b/httpcore/_async/connection.py index 59de93270..ee70cea76 100644 --- a/httpcore/_async/connection.py +++ b/httpcore/_async/connection.py @@ -93,6 +93,7 @@ async def handle_async_request(self, request: Request) -> Response: async def _connect(self, request: Request) -> AsyncNetworkStream: timeouts = request.extensions.get("timeout", {}) + sni_hostname = request.extensions.get("sni_hostname", None) timeout = timeouts.get("connect", None) retries_left = self._retries @@ -138,7 +139,8 @@ async def _connect(self, request: Request) -> AsyncNetworkStream: kwargs = { "ssl_context": ssl_context, - "server_hostname": self._origin.host.decode("ascii"), + "server_hostname": sni_hostname + or self._origin.host.decode("ascii"), "timeout": timeout, } async with Trace("connection.start_tls", request, kwargs) as trace: diff --git a/httpcore/_sync/connection.py b/httpcore/_sync/connection.py index f1fb980ae..51dbc19a6 100644 --- a/httpcore/_sync/connection.py +++ b/httpcore/_sync/connection.py @@ -93,6 +93,7 @@ def handle_request(self, request: Request) -> Response: def _connect(self, request: Request) -> NetworkStream: timeouts = request.extensions.get("timeout", {}) + sni_hostname = request.extensions.get("sni_hostname", None) timeout = timeouts.get("connect", None) retries_left = self._retries @@ -138,7 +139,8 @@ def _connect(self, request: Request) -> NetworkStream: kwargs = { "ssl_context": ssl_context, - "server_hostname": self._origin.host.decode("ascii"), + "server_hostname": sni_hostname + or self._origin.host.decode("ascii"), "timeout": timeout, } with Trace("connection.start_tls", request, kwargs) as trace: