Skip to content

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

@raptium

Description

@raptium

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:

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions