Skip to content

Commit

Permalink
Ensure that ASGI 'raw_path' does not include query component of URL. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchristie authored Dec 11, 2023
1 parent f8981f3 commit 90538a3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed

* Allow URLs where username or password contains unescaped '@'. (#2986)
* Ensure ASGI `raw_path` does not include URL query component. (#2999)

## 0.25.2 (24th November, 2023)

Expand Down
2 changes: 1 addition & 1 deletion httpx/_transports/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async def handle_async_request(
"headers": [(k.lower(), v) for (k, v) in request.headers.raw],
"scheme": request.url.scheme,
"path": request.url.path,
"raw_path": request.url.raw_path,
"raw_path": request.url.raw_path.split(b"?")[0],
"query_string": request.url.query,
"server": (request.url.host, request.url.port),
"client": self.client,
Expand Down
13 changes: 13 additions & 0 deletions tests/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ async def test_asgi_raw_path():
assert response.json() == {"raw_path": "/user@example.org"}


@pytest.mark.anyio
async def test_asgi_raw_path_should_not_include_querystring_portion():
"""
See https://github.com/encode/httpx/issues/2810
"""
async with httpx.AsyncClient(app=echo_raw_path) as client:
url = httpx.URL("http://www.example.org/path?query")
response = await client.get(url)

assert response.status_code == 200
assert response.json() == {"raw_path": "/path"}


@pytest.mark.anyio
async def test_asgi_upload():
async with httpx.AsyncClient(app=echo_body) as client:
Expand Down

0 comments on commit 90538a3

Please sign in to comment.