net-http icon indicating copy to clipboard operation
net-http copied to clipboard

Config headers to not be capitalized

Open AllanSiqueira opened this issue 2 years ago • 5 comments

Context

I am consuming a API that have case sensitive header keys. It is not common to see an case-sensitive header and also is off the specification. But sometimes it is off our control.

What I have in mind is some config to making possible to prevent the capitalize behavior and pass the header without changing it. Something like this:

http = Net::HTTP.new(endpoint.host, endpoint.port)
http.preserve_headers = true

The default behavior will remain the same, the idea is only change the behavior if this config are true.

Some workaround I can do is making a monkeypath to prevent the capitalization, but I thing it make sense to have this configuration.

I can try to implement it, but I want to know if make sense for Net::HTTP.

AllanSiqueira avatar Jul 07 '23 20:07 AllanSiqueira

I have been looking at how headers are capitalized for other reasons, and there is, fortunately, only one place where it is defined in Net::HTTPHeader#capitalize, and that module is included in Net::HTTPResponse and Net::HTTPGenericRequest.

I could imagine implementing this behavior by having some attribute in those classes which controls if capitalize is a no-op, and http.preserve_headers == true would handle setting that attribute.

technicalpickles avatar Aug 13 '23 17:08 technicalpickles

Great, I will work on it!

AllanSiqueira avatar Aug 15 '23 13:08 AllanSiqueira

@yuki24 Sorry to tag you, do you think this change make sense? Can I do something to clarify or make it better?

AllanSiqueira avatar Sep 26 '23 14:09 AllanSiqueira