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:
According to the ASGI specification 1, the
raw_pathfield is defined as:In Starlette's
TestClient, theraw_pathis directly taken from thehttpxrequest 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 ofraw_pathincludes the query string, which differs from the ASGI specification. This discrepancy was previously noted in a related issue onhttpx2.Proposed Solution:
To align with the ASGI specification, the
raw_pathin Starlette'sTestClientshould be adjusted to exclude the query string before being passed to the ASGI application.References: