Bug 58464 - servletRequest.getHeaderNames() returns all header names in lower case
Summary: servletRequest.getHeaderNames() returns all header names in lower case
Status: RESOLVED WONTFIX
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Servlet & JSP API (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-09-29 08:16 UTC by Christoph Tornau
Modified: 2015-10-05 20:28 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christoph Tornau 2015-09-29 08:16:17 UTC
The HTTP specification says that HTTP header names are case insensitive. However it would be nice if uppercase header names will be passed to the servlet without converting them to lowercase.
Comment 1 George Stanchev 2015-09-29 14:06:29 UTC
You can create a filter and an HttpServletRequestWrapper and convert them yourself. Your uppercase is my lowercase.
Comment 2 Christoph Tornau 2015-09-29 14:19:13 UTC
(In reply to George Stanchev from comment #1)
> You can create a filter and an HttpServletRequestWrapper and convert them
> yourself. Your uppercase is my lowercase.

This will probably not help because I do not know which letters are originally uppercase and which are lowercase.
Comment 3 Mark Thomas 2015-09-30 12:43:02 UTC
Tomcat stores the headers with lower case names to simplfy the lookup of headers (case sensitive rather than case insenstive lookups).

Unless there is something in one of the specifications that Tomcat implements that mandates header case is preserved (unlikely given that the HTTP spec states header names are case insensitive) this is going to get resolved as WONTFIX.
Comment 4 Christopher Schultz 2015-10-01 14:44:40 UTC
I'm not sure how many people care about this kind of thing, but I have to interact with a web service that uses JSON to pass data back and forth. The service has a way of being oddly case-insensitive in certain cases, so we have to treat all key/value pairs as if the key were case-insensitive, but I do in fact like to see what the server is actually sending.

So I've implemented a simple Map that will store the original case of the key and use that for things like Map.keySet, but also stores a case-insensitive map of the names for quick comparison/lookup.

I'm not sure what the performance implication of those additional lookups might be, or the extra garbage that would be generated for each request, but it's certainly possible to maintain the original case of the request headers and also treat them case-insensitively.

If anyone is super interested in this kind of thing, it seems like it would be easy to add a configuration option that would simply substitute a case-insensitive Map (like that which I described above) for the current lowercase-only Map.