How do I preserve case with http.get?
Based on the Tin Man's answer that the Net::HTTP
library is calling #downcase
on your custom header key (and all header keys), here are some additional options that don't monkey-patch the whole of Net::HTTP
.
You could try this:
custom_header_key = "X-miXEd-cASe"
def custom_header_key.downcase
self
end
To avoid clearing the method cache, either store the result of the above in a class-level constant:
custom_header_key = "X-miXEd-cASe"
def custom_header_key.downcase
self
end
CUSTOM_HEADER_KEY = custom_header_key
or subclass String to override that particular behavior:
class StringWithIdentityDowncase < String
def downcase
self
end
end
custom_header_key = StringWithIdentityDowncase.new("X-miXEd-cASe")
Is it possible to preserve the case of an HTTP GET request in ColdFusion MX 7?
Another option is using getParameterMap() which returns a case-sensitive structure of parameters.
<cfset map = getPageContext().getRequest().getParameterMap()>
<cfoutput>#structKeyList(map)#</cfoutput>
How to preserve custom headers case in ruby
If at all possible, I would try to change the server, which is violating HTTP standards by treating request header keys as case-sensitive - "Field names are case-insensitive". That error will mess with browsers, caches and so on.
If you can't fix it, I would probably try another HTTP client library that preserves case, not Net::HTTP. Just make sure that library doesn't use Net::HTTP behind the scenes. You could try Excon for example (I'm not sure if it preserves case but it has a lot of low-level control).
How to preserve custom headers case in ruby 2.6.5
Sorry, I needed to patch net/http as we have large existing project and its working with below code for ruby 2.5 and above
module Net::HTTPHeader
def capitalize(name)
name
end
private :capitalize
end
Are HTTP headers case-sensitive?
Header names are not case sensitive.
From RFC 2616 - "Hypertext Transfer Protocol -- HTTP/1.1", Section 4.2, "Message Headers":
Each header field consists of a name followed by a colon (":") and the field value. Field names are case-insensitive.
The updating RFC 7230 does not list any changes from RFC 2616 at this part.
Related Topics
If 'Main' Is an Instance of 'Object', Why Can't I Call It
Add Existing Classes into a Module
How to Get the Array Index or Iteration Number with an Each Iterator
How to Write to File When Using Marshal::Dump in Ruby for Object Serialization
Bootstrap Datepicker Default Value Simple_Form_For
Ruby: How to Find the Key of the Largest Value in a Hash
How to Find If Range Is Contained in an Array of Ranges
Does Ruby 1.9.2 Have an Is_A? Function
No Such File to Load -- SQLite3/Sqlite3_Native
Does Ruby Have Any Number Formatting Classes
Retrieve Number from the String Pattern Using Regular Expression
Ruby Puts Not Outputting in Real Time
Axlsx Merge Cells Inside a Style
What Are the Ruby Win32API Parameters | How to Pass a Null Pointer
How to Store Nil User's Goal in a Session