rlalfo / google-http-java-client

Automatically exported from code.google.com/p/google-http-java-client
0 stars 0 forks source link

HttpHeaders: need case insensitive get, set, and put #104

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
External references, such as a standards document, or specification?

http://javadoc.google-http-java-client.googlecode.com/hg/1.8.3-beta/com/google/a
pi/client/http/HttpHeaders.html

Java environments (e.g. Java 6, Android 2.3, App Engine, or All)?

All

Please describe the feature requested.

Unlike JSON and URL parameters, HTTP headers are case insensitive.  However, 
the get, put, and set methods from GenericData are case sensitive.  For 
example, here is an issue reported from a user:

httpRequest.getHeaders().setAccept("*/*");
httpRequest.getHeaders().set("accept", "text/plain");
httpRequest.execute();

java.lang.IllegalArgumentException: multiple headers of the same name (headers 
are case insensitive): accept
    at com.google.common.base.Preconditions.checkArgument(Preconditions.java:115)
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:750)

There are three ways I can think of that we could potentially deal with that:
1. Override get, set, and put in HttpHeaders to be case insensitive, OR
2. Add getCaseInsensitive, setCaseInsensitive, and putCaseInsensitive to 
GenericData to provide this functionality, OR
3. Force all HTTP headers to be lower case, and always toLowerCase() the HTTP 
header name in get, set, and put, perhaps adding a caseInsensitive parameter to 
GenericData to alter how it works internally for this case

Note that a case insensitive implementation for options 1 and 2 is generally 
slower than a case sensitive implementation because we have to iterate over all 
headers.

Original issue reported on code.google.com by yan...@google.com on 5 May 2012 at 6:07

GoogleCodeExporter commented 9 years ago

Original comment by mlin...@google.com on 8 May 2012 at 1:38

GoogleCodeExporter commented 9 years ago
I implemented option 3:
http://codereview.appspot.com/6235044

Original comment by yan...@google.com on 23 May 2012 at 7:42

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 24 May 2012 at 5:17