8000 Ensure that ASGI 'raw_path' does not include query component of URL. … · encode/httpx@90538a3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 90538a3

Browse files
authored
Ensure that ASGI 'raw_path' does not include query component of URL. (#2999)
1 parent f8981f3 commit 90538a3

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1313
### Fixed
1414

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

1718
## 0.25.2 (24th November, 2023)
1819

httpx/_transports/asgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ async def handle_async_request(
103103
"headers": [(k.lower(), v) for (k, v) in request.headers.raw],
104104
"scheme": request.url.scheme,
105105
"path": request.url.path,
106-
"raw_path": request.url.raw_path,
106+
"raw_path": request.url.raw_path.split(b"?")[0],
107107
"query_string": request.url.query,
108108
"server": (request.url.host, request.url.port),
109109
"client": self.client,

tests/test_asgi.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ async def test_asgi_raw_path():
120120
assert response.json() == {"raw_path": "/user@example.org"}
121121

122122

123+
@pytest.mark.anyio
124+
async def test_asgi_raw_path_should_not_include_querystring_portion():
125+
"""
126+
See https://github.com/encode/httpx/issues/2810
127+
"""
128+
async with httpx.AsyncClient(app=echo_raw_path) as client:
129+
url = httpx.URL("http://www.example.org/path?query")
130+
response = await client.get(url)
131+
132+
assert response.status_code == 200
133+
assert response.json() == {"raw_path": "/path"}
134+
135+
123136
@pytest.mark.anyio
124137
async def test_asgi_upload():
125138
async with httpx.AsyncClient(app=echo_body) as client:

0 commit comments

Comments
 (0)
0