Since I discovered that HTTP headers are case-insensive according to the RFC, i was wondering how I can access HTTP headers in a case-insensitive way with Servlets. There is a #getHeader(String) method to obtain a header but it turned out that this method treats the header fields case sensitive.
Is there a "case insensitive" way to get header fields ? Or do i have to iterate over all the header fields to find the header field I was looking for ?
The docs for getHeader(String) state: The header name is case insensitive. so it sounds like a bug in the container you're using.
Just as in HTTP/1. x, header field names are strings of ASCII characters that are compared in a case-insensitive fashion. However, header field names MUST be converted to lowercase prior to their encoding in HTTP/2.
getHeader. java.lang.String getHeader(java.lang.String name) Returns the value of the specified request header as a String . If the request did not include a header of the specified name, this method returns null . If there are multiple headers with the same name, this method returns the first head in the request.
Which servlet container are you using? The docs for getHeader(String)
state:
The header name is case insensitive.
so it sounds like a bug in the container you're using.
tomcat 8.0.24 impl of getHeader delegates to 'org.apache.tomcat.util.http.MimeHeaders' which eventually calls this method below which in turn does case insensitive check
313 public MessageBytes getValue(String name) {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With