starlette icon indicating copy to clipboard operation
starlette copied to clipboard

Mismatch Between ASGI Specification and httpx's `raw_path` Definition in TestClient

Open raptium opened this issue 5 months ago • 7 comments

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:

raptium avatar Sep 13 '24 02:09 raptium