-
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
Local address support. #100
Closed
Closed
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0faa59a
Checkpoint local address support.
bwelling 4b41aaa
Merge remote-tracking branch 'upstream/master'
bwelling 731dcf8
Change SocketAddress tuple to match expectation.
bwelling a2faecb
Add tests of setting local_addr and family.
bwelling 96cb808
Ignore spurious typing error.
bwelling 8fdc117
Fix formatting.
bwelling cc4963e
local_addr requires family
bwelling 9cd0dee
Only test IPv4; test systems don't have IPv6.
bwelling 6285d29
Update family description; reformat.
bwelling abb518f
Merge remote-tracking branch 'upstream/master'
bwelling 36acad7
Remove family and source-port support.
bwelling e634023
local_addr should be a bytes, not a str.
bwelling 3790805
Merge branch 'master' into master
tomchristie 29070ad
Merge branch 'master' into master
tomchristie 04be66b
Add missing full stop.
bwelling 91f4104
Use ternary operator to save space.
bwelling e55fb6e
Make passing of local_addr more obvious.
bwelling 9d9def2
Add a comment about future support.
bwelling 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
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import socket | ||
import ssl | ||
import typing | ||
|
||
|
@@ -204,6 +205,47 @@ async def test_http_proxy( | |
assert reason == b"OK" | ||
|
||
|
||
@pytest.mark.parametrize("family", [socket.AF_INET]) | ||
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. Probably worth just setting it below? 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. As above, this originally tested AF_INET6 also, but the test machine doesn't support IPv6. |
||
@pytest.mark.asyncio | ||
# This doesn't run with trio, since trio doesn't support family. | ||
async def test_http_request_family(family: int,) -> None: | ||
async with httpcore.AsyncConnectionPool(family=family) as http: | ||
method = b"GET" | ||
url = (b"http", b"example.org", 80, b"/") | ||
headers = [(b"host", b"example.org")] | ||
http_version, status_code, reason, headers, stream = await http.request( | ||
method, url, headers | ||
) | ||
body = await read_body(stream) | ||
|
||
assert http_version == b"HTTP/1.1" | ||
assert status_code == 200 | ||
assert reason == b"OK" | ||
assert len(http._connections[url[:3]]) == 1 # type: ignore | ||
|
||
|
||
@pytest.mark.parametrize("local_addr", ["0.0.0.0"]) | ||
@pytest.mark.asyncio | ||
# This doesn't run with trio, since trio doesn't support local_addr. | ||
async def test_http_request_local_addr(local_addr: str) -> None: | ||
family = socket.AF_INET6 if ":" in local_addr else socket.AF_INET | ||
async with httpcore.AsyncConnectionPool( | ||
family=family, local_addr=(local_addr, 0) | ||
) as http: | ||
method = b"GET" | ||
url = (b"http", b"example.org", 80, b"/") | ||
headers = [(b"host", b"example.org")] | ||
http_version, status_code, reason, headers, stream = await http.request( | ||
method, url, headers | ||
) | ||
body = await read_body(stream) | ||
|
||
assert http_version == b"HTTP/1.1" | ||
assert status_code == 200 | ||
assert reason == b"OK" | ||
assert len(http._connections[url[:3]]) == 1 # type: ignore | ||
|
||
|
||
# mitmproxy does not support forwarding HTTPS requests | ||
@pytest.mark.parametrize("proxy_mode", ["DEFAULT", "TUNNEL_ONLY"]) | ||
@pytest.mark.usefixtures("async_environment") | ||
|
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
Oops, something went wrong.
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.
Would it be reasonable to keep this as tightly constrained as possible?
Presumably
Tuple[bytes, int]
is sufficient right?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.
If source-port is removed, this type isn't needed at all, as the address could just be a
bytes
.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.
Right, yup.