Repository navigation
deprecate passing WSGI environment to parse_cookie - #3337
Merged
Merged
Conversation
davidism
force-pushed
the
deprecate-environ
branch
from
October 25, 2026 22:51
2e64c17 to
c2bc20f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
part of #3281.
parse_cookieshows a deprecation warning if a dict is passed, it should only acceptstr | None. The implementation is moved back fromsansio. That environ behavior, and some encoding behavior, seem to be the only differences. As explained below, it seems like the encoding behavior is correct in both ASGI and WSGI, and is not used by anyone so it didn't matter that ASGI (Quart) wasn't using it.In #3321 I considered deprecating (making private) the
parse_cookieanddump_cookiefunctions, in favor ofRequest.cookiesandResponse.set_cookie/delete_cookie. I've decided to leave them for now. We didn't actually remove parsing for complex headers, we just moved it into the structured header classes. There's no separate class for cookies, so the functions make sense.Interestingly, it seems no-one is using non-ASCII keys or values from Python or from browser JS. That's good, and correct according to the spec, but somewhat surprising!
http.parse_cookiedoescookie.encode('latin1').decode(). The sans-IO version does not. In WSGI, headers are latin-1 decoded strings. In ASGI, headers are bytes and you have to make an assumption about encoding. Quart assumes headers in general are UTF-8 bytes (as in, it does.decode("utf-8")). Werkzeug assumes they're ASCII (as in, it doesn't do.encode("latin-1").decode("utf-8"), it just sticks with the WSGI string).The
http.parse_cookieversion wasn't actually being used anywhere, we had replaced it insansio.Request.cookieswithsansio.http.parse_cookiein 2.0 in 2021. So apparently no one is using cookies with non-ASCII keys (or values from browser), otherwise presumably someone would have reported a breaking change since then.I did some more browser tests, since there was a todo comment about removing the encoding dance in
dump_cookie. I confirmed in Firefox and Chrome that setting a Unicode key and value produces the same.encode("utf-8").decode("latin-1")bytes thatdump_cookiedoes, soparse_cookiedoing.decode("latin-1").encode("utf-8")is correct in general, not just for WSGI's environ string behavior. This means Quart doing.decode("utf-8")on all headers is wrong, it should be doing.decode("latin-1").Made the comments clearer in both functions about this browser encoding behavior.
In the browser console, do this to test setting a Unicode key and value from the browser (instead of round trip from server).