-
Notifications
You must be signed in to change notification settings - Fork 28
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
Switch to email header parser from deprecated cgi library #195
Conversation
Hmm. Why aren't tests running?? |
@peterbe it says "2 workflows awaiting approval". You need to press the "Approve" button. |
@peterbe could be! What I see: |
@peterbe could you elaborate what you mean by that and what you did to change now? |
Co-authored-by: Sebastian Pipping <[email protected]>
Perhaps because I'm GitHub staff, I have access to a preview version of the merge-box. So mine looks different. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if tests are passing, I'm cool with it.
You, @hartwork ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peterbe I have done two things now for review:
-
Check what the HTTP 1.1 spec had to say on the value of header
Location
back then at https://datatracker.ietf.org/doc/html/rfc2616#section-14.30. Good news is it's just a URI so the change here is fine. Bad news is: It no longer has to be absolute, I'll open a dedicated issue in a minute about how that breaks hashin code (but it is unrelated to the issue at hand here). -
Play with the new code with a non-trivial example of a
Content-type
value, looks good, see below:
In [1]: content_type = 'application/json; charset="utf8"'
In [2]: import cgi
In [3]: cgi.parse_header(content_type)
Out[3]: ('application/json', {'charset': 'utf8'})
In [4]: from email.headerregistry import HeaderRegistry
In [5]: parsed = HeaderRegistry()("content-type", content_type)
In [6]: parsed.content_type
Out[6]: 'application/json'
In [7]: parsed.params['charset']
Out[7]: 'utf8'
So approving… 👍
Thanks @pib for taking us into the Python 3.13 era with hashin! 🙏
Fixes #160
Based on the answer here https://stackoverflow.com/a/77225775
Also removed the use of cgi.parse_header for the location header since as far as I can tell, that was never actually necessary.