Skip to content
Myr

Add raw_path to scope in ASGITransport (#1357)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Add raw_path to scope in ASGITransport, closes #1356 * Tweaked test

authored by Simon Willison · committed by GitHub · parent 92ca4d0 · Browse files · 2 files+20 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+20 added−0 removed

  • tests:+19 added−0 removed
  • other:+1 added−0 removed

2 files+20 added−0 removed

modified:httpx/_transports/asgi.py+1 added
88 unmodified lines
89 "method": method.decode(),90 "headers": [(k.lower(), v) for (k, v) in headers],91 "scheme": scheme.decode("ascii"),92 "path": unquote(path.decode("ascii")),93 "raw_path": path,94 "query_string": query,95 "server": (host.decode("ascii"), port),96 "client": self.client,97 "root_path": self.root_path,
64 unmodified lines
modified:tests/test_asgi.py+19 added
21 unmodified lines
22 await send({"type": "http.response.start", "status": status, "headers": headers})23 await send({"type": "http.response.body", "body": output})242526async def echo_raw_path(scope, receive, send):27 status = 20028 output = json.dumps({"raw_path": scope["raw_path"].decode("ascii")}).encode("utf-8")29 headers = [(b"content-type", "text/plain"), (b"content-length", str(len(output)))]3031 await send({"type": "http.response.start", "status": status, "headers": headers})32 await send({"type": "http.response.body", "body": output})333435async def echo_body(scope, receive, send):36 status = 20037 headers = [(b"content-type", "text/plain")]38
50 unmodified lines
89 assert response.json() == {"path": "/user@example.org"}909192@pytest.mark.usefixtures("async_environment")93async def test_asgi_raw_path():94 async with httpx.AsyncClient(app=echo_raw_path) as client:95 url = httpx.URL("http://www.example.org/").copy_with(path="/user@example.org")96 response = await client.get(url)9798 assert response.status_code == 20099 assert response.json() == {"raw_path": "/user%40example.org"}100101102@pytest.mark.usefixtures("async_environment")103async def test_asgi_upload():104 async with httpx.AsyncClient(app=echo_body) as client:105 response = await client.post("http://www.example.org/", content=b"example")106
67 unmodified lines