]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Ensure that ASGI 'raw_path' does not include query component of URL. (#2999)
authorTom Christie <tom@tomchristie.com>
Mon, 11 Dec 2023 15:45:20 +0000 (15:45 +0000)
committerGitHub <noreply@github.com>
Mon, 11 Dec 2023 15:45:20 +0000 (15:45 +0000)
CHANGELOG.md
httpx/_transports/asgi.py
tests/test_asgi.py

index cf47d0edf1f2c2d890aa282e69d1bad8c6d95484..e682c63c74b3d4617fdd4f3121a5e19d7558a6a9 100644 (file)
@@ -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)
 
index f67f0fbd5b5fb2af1a2137554bc7e9f2539c1127..08cd392f75c62b3d6aa9ee547ed9e6fc4fd702d0 100644 (file)
@@ -103,7 +103,7 @@ class ASGITransport(AsyncBaseTransport):
             "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,
index 14d6df6ded4dee3050345e0bfb8870505c444aa9..8bb6dcb7bc01d064b6cb7bd99963ae64bdc59fbb 100644 (file)
@@ -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: