Skip to content
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

Treat headers case insenitively, internally #190

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jhnstrk
Copy link
Contributor

@jhnstrk jhnstrk commented Nov 26, 2024

Converts header keys to title case before inserting into the header dict, so they are treated case-insensitively.

This seems like the easiest way, while preserving external compatibility since previous code was always assuming title case headers. However, it's not consistent with email.Message which converts to lower case.

The input headers dict for parse_form was changed to allow any type supporting get - which allows for case-insensitive dicts. It seems overkill to implement another dict type or input when we only want to get one or two values from it.

@jhnstrk
Copy link
Contributor Author

jhnstrk commented Nov 26, 2024

Fixes #165

Comment on lines +1656 to +1658
# Convert header name to title case.
header_name_tc = b"".join(header_name).decode().title()
headers[header_name_tc] = b"".join(header_value)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we actually lower case instead of title?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either would work, there's a trade off.

Lower case will require more of the code and tests to change as they currently expect title case. It also impacts the outside interface, where we say "The only required header is Content-Type." and don't say anything about the case-sensitivity of the input dict. I don't want to have to re-ingest the input header dict to ensure it's case insensitive. Switching to using only the content-type header value here would help, but entirely breaks the external API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants