[cp-patches] RFC/RFT: HTTP header handling rewrite.

Wolfgang Baer WBaer at gmx.de
Thu Mar 2 22:22:26 UTC 2006


David Daney wrote:
> Wolfgang Baer wrote:
> 
>> Nice to see you have removed that now useless inner Header class. This
>> was one
>> of the comments I wanted to make. I worked this day on mauve testcases
>> for this
>> rewrite.
>>
>> These exposed two small bugs in Headers.java:
>>
>>
>>> Index: gnu/java/net/protocol/http/Headers.java
>>> ===================================================================
>>> RCS file:
>>> /sources/classpath/classpath/gnu/java/net/protocol/http/Headers.java,v
>>> retrieving revision 1.6
>>> diff -c -p -r1.6 Headers.java
>>> *** gnu/java/net/protocol/http/Headers.java    2 Mar 2006 00:26:57
>>> -0000    1.6
>>> --- gnu/java/net/protocol/http/Headers.java    2 Mar 2006 20:40:32 -0000
>>
>>
>>
>> [...]
>>
>>
>>> ! !   /**
>>> !    * Get a new Map containing all the headers.  The keys of the Map
>>> !    * are Strings (the header names).  The values of the Map are
>>> !    * unmodifiable Lists containing Strings (the header values).
>>> !    *
>>> !    * <p>
>>> !    * !    * The returned map is modifiable.  Changing it will not
>>> effect this
>>> !    * collection of Headers in any way.
>>> !    *
>>> !    * @return a Map containing all the headers.
>>> !    */
>>> !   public Map getAsMap()
>>>    {
>>> !     LinkedHashMap m = new LinkedHashMap();
>>> !     for (Iterator it = headers.iterator(); it.hasNext(); )
>>>        {
>>> !         HeaderElement e = (HeaderElement)it.next();
>>> !         String k = e.name.toLowerCase();
>>
>>
>>
>> No lowercase here. Otherwise keys with uppercase names won't be found.
>>
>> String k = e.name;
>>
> 
> Not correct.
> 
> These Maps are only modified internally to classpath.  The RFC requires
> header name comparisons to be case insensitive.  The only way to make
> the Map work with String keys is to ensure that the keys get transformed
> to a consistant case.  When the Maps make their way into user code,
> there is no way to know the case so the only operation that makes sense
> WTR user code is iteration.  You have to know a priori that they are
> lower-cased.  I will document this.
> 

In general you are right. However SUN clearly uses the key name in the Map
returned by getHeaderFields() as it is and not lowercased. And there is nothing
in the javadoc which would make a programmer assume that he must query with
a lowercased name. So if programs use the getHeaderFields() returned Map not
only by iteration their code will break.

Wolfgang



More information about the Classpath-patches mailing list