Separate cookie headers are not parsed into Request.cookies
under HTTP/2
#2916
Unanswered
jploskey
asked this question in
Potential Issue
Replies: 1 comment 1 reply
-
Also facing this issue. doesnt follow RFC 7540 spec |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've noticed this issue when debugging a FastAPI application running under Granian, however this does seem to be a problem on the Starlette/FastAPI side. See emmett-framework/granian#539 for the original issue.
According to the HTTP/2 and ASGI specs, under HTTP/2 the client is allowed to send multiple cookie headers on a request, and ASGI should include these separate headers in the headers passed to the application; see https://asgi.readthedocs.io/en/latest/specs/www.html#http. Google Chrome, when sending requests over HTTP/2, always seems to send cookies using multiple cookie headers, which is how I discovered this issue.
Currently, when trying to access
Request.cookies
, only the first "Cookie" header is taken into account. While this makes sense for HTTP/1.1, when the HTTP version is 2.0 the additional headers should probably be parsed out as well.Example
Expected Output (All three cookies are parsed out):
Actual Output (Only the first cookie is available):
Relevant code is here in
starlette.datastructures:Headers
:Under HTTP/2 we could use
self.headers.getlist("cookie")
, parse each value with cookie_parser, and merge all of them into a single dictionary.Beta Was this translation helpful? Give feedback.
All reactions