Wolfgang Baer wrote:
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.


What do they do if there are two headers where the name differs only by case? Does it have two entries in the map or only one? What happens when you do a get on the map with a key of the wrong case?

On the map returned by Sun is it possible to find a String s where

map.containsKey(s) == true

but where:

found = false;
for (Iterator it = map.keySet().iterator; it.hasNext(); ) {
  String k = (String)it.next();
  if (k.equals(s)) {found = true; break;}
}

Results in found having a value of false?


Or I guess put more succinctly: Can the map (with String keys) be queried (with Map.get()) in a case insensitive manner?

I really don't want to use a case insensitive horked up map, but I guess we can if it is necessary.

David Daney.

Reply via email to