starlette
starlette copied to clipboard
Mismatch Between ASGI Specification and httpx's `raw_path` Definition in TestClient
According to the ASGI specification 1, the raw_path
field is defined as:
raw_path (byte string) – The original HTTP path component, excluding any query string, unmodified from the bytes that were received by the web server.
In Starlette's TestClient
, the raw_path
is directly taken from the httpx
request without modification:
https://github.com/encode/starlette/blob/2d0dde8defe9e3d4df0baacdb20faf273152f1cb/starlette/testclient.py#L307 https://github.com/encode/starlette/blob/2d0dde8defe9e3d4df0baacdb20faf273152f1cb/starlette/testclient.py#L254
However, httpx
's definition of raw_path
includes the query string, which differs from the ASGI specification. This discrepancy was previously noted in a related issue on httpx
2.
Proposed Solution:
To align with the ASGI specification, the raw_path
in Starlette's TestClient
should be adjusted to exclude the query string before being passed to the ASGI application.
References:
- [1] ASGI Specification: https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scope
- [2] Related httpx Issue: https://github.com/encode/httpx/issues/2810