I am having Rest service exposed (using Spring framework ) where in I am trying to access custom http headers. When I am retrieving the headers in the controller class , Strange thing I observed is that spring framework is converting case of header names to camel case.
For example if I call rest service from soap UI by passing the http header name as "RAVIKUMAR" in caps , what I am seeing in the controller class, header name is now "RaviKumar" .
I know as per http spec , header names are case-insensitive. But I want to see the logic how spring framework is playing with header names . Does anyone know which class in Spring has this logic ?
I tried to have a look and related class but could not find the place where its converting the headernames to camel case.
It must be doing a case-insensitive comparison of your all-upper-case names to an existing set of names which happen to be in camel-case already. Otherwise it would have no way of knowing that RAVIKUMAR should be converted to RaviKumar instead of RavikUmar or RavIkUmar or any other camel-case version.
Agree with Paul, there's something else going on here. Spring has no way of knowing that Kumar is a differrent word. Spring might make standard HttpHeaders into camelcase, or rather just give you the hard coded header name
Any hoo, according to specification, HTTP headers names are suppossed to be case-insensitive. From here
HTTP header fields, which include general-header (section 4.5), request-header (section 5.3), response-header (section 6.2), and entity-header (section 7.1) fields, follow the same generic format as that given in Section 3.1 of RFC 822 . Each header field consists of a name followed by a colon (":") and the field value. Field names are case-insensitive
If you are doing something that requires the http header to be case sensitive, then you are doing it wrong. HTTP proxies can and might modify the HTTP headers. It may not be Spring that is changing your header, but some proxy in between that changes the header. Even if the firewall in your local environment is not doing that today, there's no guarantee that the client' firewall will not do that too
posted 5 years ago
Thank you Paul/Jayesh.
I agree that there might be something else . Is there any way that I can find out what that "something else" is which might be doing it. ?
Initially I thought may be its the SOAP UI tool itself from where I am testing the rest service call is doing that, Then I tested with chrome web store rest console. Same issue persisted and strangely Its not happening for all the header-names. I ran few tests on some of the headers
Actual Header name is LANGUAGEINTERPRETERREQUIRED and its getting Converted to LanguageinterpreterRequired Actual Header name is MEDSTARTDATE and its getting Converted to MedStartDate
The only way you are going to know is by finding where it is happenning. (Well, duh!!) It could happen in the client, over the wire, within spring, or within your own code. You will have to look at each thing on it's own to figure out. Looks like you already attempted to do that by using a differrent client. You will have to do this with each component in the chain. FOr example, you can put a HTTP sniffer at both ends to see if something is happenning over the wire. You could write a very simple dummy controller to see if this happens in Spring. If you can zero in Spring, then you will have to debug inside Spring to know why exactly this is happenning. Debugging Spring will be interesting for you, but I am pretty sure it will be pointless
Which brings me to the other point that I made earlier: Why do you care if it's camel case? You should consider header names to be case insensitive.
Trust God, but always tether your camel... to this tiny ad.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop