I’m doing an http request in ruby:
http = Net::HTTP.new(uri.host, uri.port)
req = Net::HTTP::Post.new(uri.path)
req.body = payload
req['customeheader'] = 'xxxxxxxxx'
http.set_debug_output $stdout
I have debug switched on and when the request is posted I can see the header is being posted as:
Customheader: xxxxxxxxx
Is there anyway to stop this, the third party server I’m posting to is giving an error because the header name isn’t correct – it’s expecting customheader:
According to the HTTP spec (RFC 2616), header field names are case-insensitive. So the third-party server has a broken implementation.
If you really needed to, you could monkey-patch Net::HTTP to preserve case, because it downcases the field names when it stores them and then writes them with initial caps.
Here’s the storage method you used (
Net::HTTPHeader#[]=):And here is where it writes the header (
Net::HTTPGenericRequest#write_header):Those are likely the only methods you’d need to override, but I’m not 100% certain.