How to Preserve Case with Http.Get

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



Leave a reply



Submit