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

Downcase Content-Type charset name #753

Merged
merged 1 commit into from Jun 2, 2023

Conversation

paul
Copy link
Contributor

@paul paul commented Jun 1, 2023

Ran into an issue making requests to a server I don't control (Microsoft ASP.NET) where it was giving me errors POSTing JSON with HTTP.post(path, json: {whatever}).

This header works: Content-Type: application/json; charset=utf-8
This did not: Content-Type: application/json; charset=UTF-8

HTTP.rb uses Ruby String#encoding.name, which returns "UTF" in all caps, which is causing the charset=UTF-8.

MDN says "Case insensitive, lowercase preferred", so I just downcased the encoding name, and added a test.

Ran into an issue making requests to a server I don't control (Microsoft
ASP.NET) where it was giving me errors POSTing JSON.

This header works: `Content-Type: application/json; charset=utf-8`
This did not: `Content-Type: application/json; charset=UTF-8`

HTTP.rb uses Ruby `String#encoding.name`, which returns "UTF" in all
caps, which is causing the `charset=UTF-8`.

[MDN says "Case insensitive, lowercase
preferred"](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type),
so I just downcased the encoding name, and added a test.
@paul paul force-pushed the downcase-charset-encoding branch from 1941bdd to 326ccb0 Compare June 1, 2023 21:43
Copy link

@jxc jxc left a comment

Choose a reason for hiding this comment

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

lgtm!

@tarcieri tarcieri requested a review from ixti June 1, 2023 22:02
Copy link
Member

@ixti ixti left a comment

Choose a reason for hiding this comment

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

LGTM. thank you!

@ixti ixti merged commit 9bfcdfb into httprb:main Jun 2, 2023
8 checks passed
@paul paul deleted the downcase-charset-encoding branch June 2, 2023 17:28
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.

None yet

4 participants