Wolfgang Baer wrote:
David Daney wrote:

Wolfgang Baer wrote:

[...]

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?


Depends if you use getHeaderFields() to get a Map first or if you directly
query with getHeaderField(String). See example below.


Does it have two entries in the map or only one?


In the Map - two.


What happens when you do a get on the map with a key of the wrong case?


Returns null.

An example:

Suppose a server returns the following set of headers. Notice that
the last two are lowercase.

HTTP/1.0 200 OK
Server: TestServer
Key: value
Key: value1
key: value2
key: value3

For getHeaderFields() Sun will return a Map with size 4

Key [value1, value]
key [value3, value2]
null [HTTP/1.0 200 OK]
Server [TestServer]

So they are treated (for getHeaderFields ONLY) case sensitiv !

For getHeaderField() Sun treats them case-insensitive according
to the RFC. This leads to:

getHeaderField("Key") and getHeaderField("key") will both return "value3"
as this is the last value received.


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?


No - if the key is found in the map it will also be found by iteration.


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


No


Thanks for doing all the hard work. It looks like *all* your suggested changes to the patch are correct.


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


I don't understand this one. Don't you mean case sensitive here ?
What does horked up mean - can't find it in any dictionary.


'Horked up' is a term used by (perhaps a small set of) native English speakers to confuse people. It roughly means: In an aesthetically unpleasing manner.

David Daney.



Reply via email to