Skip to content

Commit

Permalink
Add sni_hostname extension
Browse files Browse the repository at this point in the history
  • Loading branch information
karpetrosyan committed May 22, 2023
1 parent 6528f56 commit 1e4d1c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion httpcore/_async/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion httpcore/_sync/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1e4d1c9

Please sign in to comment.