Skip to content

Commit 56c0e4f

Browse files
Support sni_hostname extension with SOCKS proxy. (#774)
* 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 <[email protected]>
1 parent bb51381 commit 56c0e4f

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
77
## Unreleased
88

99
- Add support for HTTPS proxies. Currently only available for async. (#745)
10+
- Handle `sni_hostname` extension with SOCKS proxy. (#774)
1011
- Change the type of `Extensions` from `Mapping[Str, Any]` to `MutableMapping[Str, Any]`. (#762)
1112
- Handle HTTP/1.1 half-closed connections gracefully. (#641)
1213
- Drop Python 3.7 support. (#727)

httpcore/_async/socks_proxy.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def __init__(
216216

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

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

259260
kwargs = {
260261
"ssl_context": ssl_context,
261-
"server_hostname": self._remote_origin.host.decode("ascii"),
262+
"server_hostname": sni_hostname
263+
or self._remote_origin.host.decode("ascii"),
262264
"timeout": timeout,
263265
}
264266
async with Trace("start_tls", logger, request, kwargs) as trace:

httpcore/_sync/socks_proxy.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def __init__(
216216

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

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

259260
kwargs = {
260261
"ssl_context": ssl_context,
261-
"server_hostname": self._remote_origin.host.decode("ascii"),
262+
"server_hostname": sni_hostname
263+
or self._remote_origin.host.decode("ascii"),
262264
"timeout": timeout,
263265
}
264266
with Trace("start_tls", logger, request, kwargs) as trace:

0 commit comments

Comments
 (0)