Skip to content
Myr

Force lowercase ASGI headers (#1351)

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 7fda99f · Browse files · 2 files+29 added−1 removed
This commit

State

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

Trailers

  • Co-authored-by: Florimond Manca <florimond.manca@gmail.com>

Diff stats

2 files+29 added−1 removed

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

2 files+29 added−1 removed

modified:httpx/_transports/asgi.py+1 added-1 removed
85 unmodified lines
86 "type": "http",87 "asgi": {"version": "3.0"},88 "http_version": "1.1",89 "method": method.decode(),90 "headers": headers,90 "headers": [(k.lower(), v) for (k, v) in headers],91 "scheme": scheme.decode("ascii"),92 "path": unquote(path.decode("ascii")),93 "query_string": query,94 "server": (host.decode("ascii"), port),
66 unmodified lines
modified:tests/test_asgi.py+28 added
34 unmodified lines
35 more_body = message.get("more_body", False)36 await send({"type": "http.response.body", "body": body, "more_body": more_body})373839async def echo_headers(scope, receive, send):40 status = 20041 output = json.dumps(42 {"headers": [[k.decode(), v.decode()] for k, v in scope["headers"]]}43 ).encode("utf-8")44 headers = [(b"content-type", "text/plain"), (b"content-length", str(len(output)))]4546 await send({"type": "http.response.start", "status": status, "headers": headers})47 await send({"type": "http.response.body", "body": output})484950async def raise_exc(scope, receive, send):51 raise RuntimeError()5253
35 unmodified lines
89 assert response.text == "example"909192@pytest.mark.usefixtures("async_environment")93async def test_asgi_headers():94 async with httpx.AsyncClient(app=echo_headers) as client:95 response = await client.get("http://www.example.org/")9697 assert response.status_code == 20098 assert response.json() == {99 "headers": [100 ["host", "www.example.org"],101 ["accept", "*/*"],102 ["accept-encoding", "gzip, deflate, br"],103 ["connection", "keep-alive"],104 ["user-agent", f"python-httpx/{httpx.__version__}"],105 ]106 }107108109@pytest.mark.usefixtures("async_environment")110async def test_asgi_exc():111 async with httpx.AsyncClient(app=raise_exc) as client:112 with pytest.raises(RuntimeError):113 await client.get("http://www.example.org/")
41 unmodified lines