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:
While it's possible to monkey patch Net::HTTPHeader and Net:HTTPGenericRequest to remove the downcase and capitalize, I found a different approach that allows selective case sensitivity rather than forcing everything.
The solution:
class CaseSensitiveString < String
def downcase
self
end
def capitalize
self
end
end
Then CaseSensitiveString.new('keyname') to create your keys when they are case sensitive. Use strings/symbols for other keys to maintain existing behaviour. This is much simpler than the monkey patching and works well with the rest-client library as well as Net::HTTP.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With