-
-
Notifications
You must be signed in to change notification settings - Fork 931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mismatch Between ASGI Specification and httpx's raw_path
Definition in TestClient
#2692
Comments
Do you have an MRE? |
I've added a test case in def test_raw_path_with_querystring(test_client_factory: TestClientFactory) -> None:
async def app(scope: Scope, receive: Receive, send: Send) -> None:
raw_path = scope.get("raw_path")
assert raw_path is not None
response = PlainTextResponse(f"raw_path: {raw_path}")
await response(scope, receive, send)
client = test_client_factory(app)
response = client.get("/hello world", params={"foo": "bar"})
assert response.text == "raw_path: b'/hello%20world'" This issue specifically affects I'm planning to submit a PR with a one-line fix along with the above test case. Additionally, it's worth noting that the Given this ambiguity, I've left |
Can you create an issue in the asgiref repository about this divergence? |
django/asgiref#468 is created about the divergence between HTTP and WebSocket. |
I saw it. Thanks. |
Do you know if uvicorn needs to be fixed as well? Also, PR is welcome. |
PR submitted. |
According to the ASGI specification 1, the
raw_path
field is defined as:In Starlette's
TestClient
, theraw_path
is directly taken from thehttpx
request without modification:starlette/starlette/testclient.py
Line 307 in 2d0dde8
starlette/starlette/testclient.py
Line 254 in 2d0dde8
However,
httpx
's definition ofraw_path
includes the query string, which differs from the ASGI specification. This discrepancy was previously noted in a related issue onhttpx
2.Proposed Solution:
To align with the ASGI specification, the
raw_path
in Starlette'sTestClient
should be adjusted to exclude the query string before being passed to the ASGI application.References:
raw_path
scope key should not include the query string portion. httpx#2810The text was updated successfully, but these errors were encountered: