request headers unexpected behaviour #2941
Answered
by
santibreo
santibreo
asked this question in
Potential Issue
-
Hi! I am trying to test an API with the following code: from starlette.requests import Request
key = 'Authorization'
request = Request(scope={'type': 'http', 'headers': [(key.encode(), b'Bearer token')]})
request.headers
# Output:
# Headers({'Authorization': 'Bearer token'})
request.headers.get(key)
# Output:
# None
[k for k in request.headers][0] == key
# Output:
# True
dict(request.headers.items()).get(key)
# Output:
# 'Bearer token' Is this behaviour expected? I am using starlette version 0.46.2 Any help is welcome 🙂 |
Beta Was this translation helpful? Give feedback.
Answered by
santibreo
May 21, 2025
Replies: 1 comment
-
It is because header key must be lowercased 🙈 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
santibreo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is because header key must be lowercased 🙈