Skip to content
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 2 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions httpx/_transports/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ async def arequest(
"headers": [(k.lower(), v) for (k, v) in headers],
"scheme": scheme.decode("ascii"),
"path": unquote(path.decode("ascii")),
"raw_path": path,
"query_string": query,
"server": (host.decode("ascii"), port),
"client": self.client,
Expand Down
19 changes: 19 additions & 0 deletions tests/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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:
Expand Down