mirror of https://github.com/apache/jclouds.git
Made getting a header by field-name case-insensitive to address the issue from
https://groups.google.com/forum/?fromgroups#!topic/jclouds/lEZjqhbudX4 This is the proper way to handle it as RFC 2616, "Hypertext Transfer Protocol -- HTTP/1.1", Section 4.2, "Message Headers" states, Each header field consists of a name followed by a colon (":") and the field value. Field names are case-insensitive.
This commit is contained in:
parent
aff96befbe
commit
8d9499b3c1
|
@ -32,6 +32,7 @@ import org.jclouds.util.Multimaps2;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.base.Objects.ToStringHelper;
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
|
import com.google.common.collect.HashMultimap;
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
|
@ -185,13 +186,25 @@ public class HttpMessage extends PayloadEnclosingImpl {
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Multimap<String, String> getLowercaseHeaders() {
|
||||||
|
Multimap<String, String> lowercaseHeaders = HashMultimap.create(getHeaders().keys().size(), 1);
|
||||||
|
|
||||||
|
for (String header: getHeaders().keys()) {
|
||||||
|
for (String value: getHeaders().get(header)) {
|
||||||
|
lowercaseHeaders.put(header.toLowerCase(), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lowercaseHeaders;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* try to get the value, then try as lowercase.
|
* try to get the value, then try as lowercase.
|
||||||
*/
|
*/
|
||||||
public String getFirstHeaderOrNull(String string) {
|
public String getFirstHeaderOrNull(String string) {
|
||||||
Collection<String> values = headers.get(string);
|
Collection<String> values = headers.get(string);
|
||||||
if (values.size() == 0)
|
if (values.size() == 0)
|
||||||
values = headers.get(string.toLowerCase());
|
values = getLowercaseHeaders().get(string.toLowerCase());
|
||||||
return (values.size() >= 1) ? values.iterator().next() : null;
|
return (values.size() >= 1) ? values.iterator().next() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue