Skip to content

Commit

Permalink
Support sni_hostname extension with SOCKS proxy. (#774)
Browse files Browse the repository at this point in the history
* Handle `sni_hostname` extension when SOCKS proxy is activated.

* Add tests.

* Reformat the test.

* Run linting checks locally and reformat again.

* Update changelog and add a missing test.

* Update tests/_async/test_socks_proxy.py

* Update tests/_sync/test_socks_proxy.py

---------

Co-authored-by: Tom Christie <tom@tomchristie.com>
  • Loading branch information
Allgot and tomchristie committed Sep 1, 2023
1 parent bb51381 commit 56c0e4f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## Unreleased

- Add support for HTTPS proxies. Currently only available for async. (#745)
- Handle `sni_hostname` extension with SOCKS proxy. (#774)
- Change the type of `Extensions` from `Mapping[Str, Any]` to `MutableMapping[Str, Any]`. (#762)
- Handle HTTP/1.1 half-closed connections gracefully. (#641)
- Drop Python 3.7 support. (#727)
Expand Down
4 changes: 3 additions & 1 deletion httpcore/_async/socks_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def __init__(

async def handle_async_request(self, request: Request) -> Response:
timeouts = request.extensions.get("timeout", {})
sni_hostname = request.extensions.get("sni_hostname", None)
timeout = timeouts.get("connect", None)

async with self._connect_lock:
Expand Down Expand Up @@ -258,7 +259,8 @@ async def handle_async_request(self, request: Request) -> Response:

kwargs = {
"ssl_context": ssl_context,
"server_hostname": self._remote_origin.host.decode("ascii"),
"server_hostname": sni_hostname
or self._remote_origin.host.decode("ascii"),
"timeout": timeout,
}
async with Trace("start_tls", logger, request, kwargs) as trace:
Expand Down
4 changes: 3 additions & 1 deletion httpcore/_sync/socks_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def __init__(

def handle_request(self, request: Request) -> Response:
timeouts = request.extensions.get("timeout", {})
sni_hostname = request.extensions.get("sni_hostname", None)
timeout = timeouts.get("connect", None)

with self._connect_lock:
Expand Down Expand Up @@ -258,7 +259,8 @@ def handle_request(self, request: Request) -> Response:

kwargs = {
"ssl_context": ssl_context,
"server_hostname": self._remote_origin.host.decode("ascii"),
"server_hostname": sni_hostname
or self._remote_origin.host.decode("ascii"),
"timeout": timeout,
}
with Trace("start_tls", logger, request, kwargs) as trace:
Expand Down

0 comments on commit 56c0e4f

Please sign in to comment.