httprb / http

HTTP (The Gem! a.k.a. http.rb) - a fast Ruby HTTP client with a chainable API, streaming support, and timeouts
MIT License
3k stars 321 forks source link

Downcase Content-Type charset name #753

Closed paul closed 1 year ago

paul commented 1 year ago

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.