Wolfgang Baer wrote:
! ! /**! * 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 requiresheader name comparisons to be case insensitive. The only way to makethe Map work with String keys is to ensure that the keys get transformedto 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 senseWTR 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 notonly by iteration their code will break.
The solution would appear to be not to use a LinkedHashMap but some new class, similar to gnu.inet.http.Headers, that implements Map but does case-insensitive lookups on the keys (returning the header names in their original case in keySet() etc).
-- 犬 Chris Burdess "They that can give up essential liberty to obtain a little safety deserve neither liberty nor safety." - Benjamin Franklin
PGP.sig
Description: This is a digitally signed message part
