-
-
Notifications
You must be signed in to change notification settings - Fork 858
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
Add raw_path to scope in ASGITransport #1357
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,15 @@ async def echo_path(scope, receive, send): | |
await send({"type": "http.response.body", "body": output}) | ||
|
||
|
||
async def echo_raw_path(scope, receive, send): | ||
status = 200 | ||
output = json.dumps({"raw_path": repr(scope["raw_path"])}).encode("utf-8") | ||
headers = [(b"content-type", "text/plain"), (b"content-length", str(len(output)))] | ||
|
||
await send({"type": "http.response.start", "status": status, "headers": headers}) | ||
await send({"type": "http.response.body", "body": output}) | ||
|
||
|
||
async def echo_body(scope, receive, send): | ||
status = 200 | ||
headers = [(b"content-type", "text/plain")] | ||
|
@@ -80,6 +89,16 @@ async def test_asgi_urlencoded_path(): | |
assert response.json() == {"path": "/[email protected]"} | ||
|
||
|
||
@pytest.mark.usefixtures("async_environment") | ||
async def test_asgi_raw_path(): | ||
async with httpx.AsyncClient(app=echo_raw_path) as client: | ||
url = httpx.URL("http://www.example.org/").copy_with(path="/[email protected]") | ||
response = await client.get(url) | ||
|
||
assert response.status_code == 200 | ||
assert response.json() == {"raw_path": "b'/user%40example.org'"} | ||
|
||
|
||
@pytest.mark.usefixtures("async_environment") | ||
async def test_asgi_upload(): | ||
async with httpx.AsyncClient(app=echo_body) as client: | ||
|
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.
I'm using
repr(scope["raw_path"])
here as an easy way to confirm that the value is indeed a Python bytestring - it ends up being returned as"b'/user%40example.org'"
in the JSON.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.
Yup that make sense.
I guess it might look a bit confusing to future readers, so we could either:
{"raw_path": scope["raw_path"].decode("ascii")}
I'd marginally prefer (2), since it's actually perfectly sufficient here, but I'm okay enough with either.