Skip to content
Myr

Fix ASGITransport path escaping (#1307)

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

authored by Tom Christie · committed by GitHub · parent c923f1a · Browse files · 2 files+23 added−1 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+23 added−1 removed

  • tests:+21 added−0 removed
  • other:+2 added−1 removed

2 files+23 added−1 removed

modified:httpx/_transports/asgi.py+2 added-1 removed
1from typing import TYPE_CHECKING, Callable, List, Optional, Tuple, Union2from urllib.parse import unquote34import httpcore5import sniffio6
81 unmodified lines
88 "http_version": "1.1",89 "method": method.decode(),90 "headers": headers,91 "scheme": scheme.decode("ascii"),91 "path": path.decode("ascii"),92 "path": unquote(path.decode("ascii")),93 "query_string": query,94 "server": (host.decode("ascii"), port),95 "client": self.client,96 "root_path": self.root_path,
64 unmodified lines
modified:tests/test_asgi.py+21 added
1import json23import pytest45import httpx6
6 unmodified lines
13 await send({"type": "http.response.start", "status": status, "headers": headers})14 await send({"type": "http.response.body", "body": output})151617async def echo_path(scope, receive, send):18 status = 20019 output = json.dumps({"path": scope["path"]}).encode("utf-8")20 headers = [(b"content-type", "text/plain"), (b"content-length", str(len(output)))]2122 await send({"type": "http.response.start", "status": status, "headers": headers})23 await send({"type": "http.response.body", "body": output})242526async def echo_body(scope, receive, send):27 status = 20028 headers = [(b"content-type", "text/plain")]29
29 unmodified lines
59 assert response.text == "Hello, World!"606162@pytest.mark.usefixtures("async_environment")63async def test_asgi_urlencoded_path():64 async with httpx.AsyncClient(app=echo_path) as client:65 url = httpx.URL("http://www.example.org/").copy_with(path="/user@example.org")66 response = await client.get(url)6768 assert response.status_code == 20069 assert response.json() == {"path": "/user@example.org"}707172@pytest.mark.usefixtures("async_environment")73async def test_asgi_upload():74 async with httpx.AsyncClient(app=echo_body) as client:75 response = await client.post("http://www.example.org/", content=b"example")76
50 unmodified lines