-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support sni_hostname
extension with SOCKS proxy.
#774
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
87b9a5e
Handle `sni_hostname` extension when SOCKS proxy is activated.
Allgot 704d7d0
Add tests.
Allgot e6b274c
Reformat the test.
Allgot d3a801c
Run linting checks locally and reformat again.
Allgot 6fd2641
Update changelog and add a missing test.
Allgot 3572973
Update tests/_async/test_socks_proxy.py
tomchristie 2516328
Update tests/_sync/test_socks_proxy.py
tomchristie 4ad1111
Merge branch 'master' into support-sni-hostname-socks
tomchristie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,3 +191,66 @@ async def test_socks5_request_incorrect_auth(): | |
assert str(exc_info.value) == "Invalid username/password" | ||
|
||
assert not proxy.connections | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_socks5_sni_hostname(): | ||
""" | ||
Send an HTTP request via a SOCKS proxy utilizing `sni_hostname` extension. | ||
""" | ||
network_backend = httpcore.AsyncMockBackend( | ||
[ | ||
# The initial socks CONNECT | ||
# v5 NOAUTH | ||
b"\x05\x00", | ||
# v5 SUC RSV IP4 127 .0 .0 .1 :80 | ||
b"\x05\x00\x00\x01\xff\x00\x00\x01\x00\x50", | ||
# The actual response from the remote server | ||
b"HTTP/1.1 200 OK\r\n", | ||
b"Content-Type: plain/text\r\n", | ||
b"Content-Length: 13\r\n", | ||
b"\r\n", | ||
b"Hello, world!", | ||
] | ||
) | ||
|
||
async with httpcore.AsyncSOCKSProxy( | ||
proxy_url="socks5://localhost:8080/", | ||
network_backend=network_backend, | ||
) as proxy: | ||
# Sending an intial request, which once complete will return to the pool, IDLE. | ||
async with proxy.stream( | ||
"GET", | ||
"https://93.184.216.34/", | ||
headers=[(b"Host", "example.com")], | ||
extensions={"sni_hostname": "example.com"}, | ||
) as response: | ||
info = [repr(c) for c in proxy.connections] | ||
assert info == [ | ||
"<AsyncSocks5Connection ['https://93.184.216.34:443', HTTP/1.1, ACTIVE, Request Count: 1]>" | ||
] | ||
await response.aread() | ||
|
||
assert response.status == 200 | ||
assert response.content == b"Hello, world!" | ||
info = [repr(c) for c in proxy.connections] | ||
assert info == [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this |
||
"<AsyncSocks5Connection ['https://93.184.216.34:443', HTTP/1.1, IDLE, Request Count: 1]>" | ||
] | ||
assert proxy.connections[0].is_idle() | ||
assert proxy.connections[0].is_available() | ||
assert not proxy.connections[0].is_closed() | ||
|
||
# A connection on a tunneled proxy can only handle HTTPS requests to the same origin. | ||
assert not proxy.connections[0].can_handle_request( | ||
httpcore.Origin(b"http", b"93.184.216.34", 80) | ||
) | ||
assert not proxy.connections[0].can_handle_request( | ||
httpcore.Origin(b"http", b"other.com", 80) | ||
) | ||
assert proxy.connections[0].can_handle_request( | ||
httpcore.Origin(b"https", b"93.184.216.34", 443) | ||
) | ||
assert not proxy.connections[0].can_handle_request( | ||
httpcore.Origin(b"https", b"other.com", 443) | ||
) | ||
tomchristie marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this check