-
-
Notifications
You must be signed in to change notification settings - Fork 844
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add raw_path to scope in ASGITransport (#1357)
* Add raw_path to scope in ASGITransport, closes #1356 * Tweaked test
- Loading branch information
Showing
2 changed files
with
20 additions
and
0 deletions.
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": scope["raw_path"].decode("ascii")}).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": "/user%40example.org"} | ||
|
||
|
||
@pytest.mark.usefixtures("async_environment") | ||
async def test_asgi_upload(): | ||
async with httpx.AsyncClient(app=echo_body) as client: | ||
|