• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

custom http headers in rest service

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/main/java/org/springframework/http/HttpHeaders.java

There is one place where it seems that its converting the headernames to lower case but not to camel case.

https://github.com/spring-projects/spring-framework/blob/master/spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java

Any help in this regard will be highly appreciated.
 
Marshal
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 [9]. 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
 
Ravi Bansal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jayesh A Lalwani
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!