-
-
Notifications
You must be signed in to change notification settings - Fork 947
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
Case Sensitive Headers in httpx #1067
Comments
Ah right, it is actually an httpx bug, in the ASGITransport class. Since 0.16. The ASGI spec mandates that headers in the scope must be lowercased, which is no longer the case. The ASGITransport class in httpx now needs to explicitly lowercase whatever headers are passed to it. |
So I need to create an Issue within httpx? Thanks for your immediate response |
I ran into this issue in exactly the same way -- using HTTPX to unittest FastAPI. Thanks for the thorough investigation, @dhofstetter! |
Closed via encode/httpx#1351 and released as httpx 0.16.1 |
Checklist
master
.Describe the bug
In the project httpx there has been a new version released. They propagate the request.headers now in a case sensitive manner.
Within starlette (or in my case fastapi) this lead to unwanted behaviour as I'm unable now to determine wether or not headers are present.
The problem is, that if you check within starlette or fastapi for a header being present, the comparison is expected to be performed as lowercase comparison:
The problem is that the fields are propagated using the scope param:
so there is no mutation of the given variable. As scope['headers'] is going to be "request.headers.raw" from httpx (see _client.py within httpx package):
there is now a problem when comparing Header values.
To reproduce
Expected behavior
the expected behaviour is, that starlette changes the Header class initialization in a way, that headers received get definetly lowercased. Or starlette should not use the headers.raw field.
So that request.headers contains only keys in lowercase and any checks for existing headers succeed.
Actual behavior
Now the headers field within the request within starlette contains header values that are stored lowercased. Therefore any check for headers existing may fail, except they are passed as lowercase values (which was the behaviour until httpx version 0.15.5)
I hope you can understand the problem.
p.s. probably this behaviour is special to my use case. I use httpx and it's AsyncClient to write unit tests against my starlette/fastapi application (I'm not sure if this changes the way how requests get handled).
BR Daniel
The text was updated successfully, but these errors were encountered: