You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by an...@apache.org on 2013/07/30 02:25:25 UTC
git commit: JCLOUDS-155: Making header handling in OpenStack
case-insensitive
Updated Branches:
refs/heads/fix-jclouds-155 [created] b86371236
JCLOUDS-155: Making header handling in OpenStack case-insensitive
Submitted by Rodney Beede
Project: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/commit/b8637123
Tree: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/tree/b8637123
Diff: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/diff/b8637123
Branch: refs/heads/fix-jclouds-155
Commit: b863712368d66d9ea1b74b3fd799fad3e653611f
Parents: f6b5b67
Author: Andrew Phillips <an...@apache.org>
Authored: Mon Jul 29 20:24:15 2013 -0400
Committer: Andrew Phillips <an...@apache.org>
Committed: Mon Jul 29 20:24:15 2013 -0400
----------------------------------------------------------------------
...ParseAuthenticationResponseFromHeadersTest.java | 13 ++++++++++++-
common/openstack/pom.xml | 5 +++++
.../ParseAuthenticationResponseFromHeaders.java | 17 ++++++++++-------
3 files changed, 27 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/b8637123/apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java
----------------------------------------------------------------------
diff --git a/apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java b/apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java
index 85ae254..200cdfe 100644
--- a/apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java
+++ b/apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java
@@ -60,7 +60,18 @@ public class ParseAuthenticationResponseFromHeadersTest {
.addHeader("X-Storage-Url", "http://127.0.0.1:8080/v1/token").build();
AuthenticationResponse md = parser.apply(response);
- assertEquals(md, new AuthenticationResponse("token", ImmutableMap.<String, URI> of("X-Storage-Url", URI
+ assertEquals(md, new AuthenticationResponse("token", ImmutableMap.<String, URI> of("X-Storage-Url".toLowerCase(), URI
.create("http://fooman:8080/v1/token"))));
+
+
+ // Additional test that verifies that the case insensitive header "X-Storage-Url" is actually replaced
+ // https://issues.apache.org/jira/browse/JCLOUDS-155
+ response = HttpResponse.builder().statusCode(204).message("No Content")
+ .addHeader("X-Auth-Token".toLowerCase(), "token")
+ .addHeader("X-Storage-Token".toLowerCase(), "token")
+ .addHeader("X-Storage-Url".toLowerCase(), "http://127.0.0.1:8080/v1/token").build();
+ md = parser.apply(response);
+ assertEquals(md, new AuthenticationResponse("token", ImmutableMap.<String, URI> of("X-Storage-Url".toLowerCase(), URI
+ .create("http://fooman:8080/v1/token"))));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/b8637123/common/openstack/pom.xml
----------------------------------------------------------------------
diff --git a/common/openstack/pom.xml b/common/openstack/pom.xml
index dce8613..52bd657 100644
--- a/common/openstack/pom.xml
+++ b/common/openstack/pom.xml
@@ -50,6 +50,11 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2.1</version>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/b8637123/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java
----------------------------------------------------------------------
diff --git a/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java b/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java
index aa988fb..c1f94ed 100644
--- a/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java
+++ b/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java
@@ -35,8 +35,7 @@ import org.jclouds.rest.InvocationContext;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableMap.Builder;
+import org.apache.commons.collections.map.CaseInsensitiveMap;
/**
* This parses {@link AuthenticationResponse} from HTTP headers.
@@ -54,15 +53,19 @@ public class ParseAuthenticationResponseFromHeaders implements Function<HttpResp
/**
* parses the http response headers to create a new {@link AuthenticationResponse} object.
*/
+ @SuppressWarnings("unchecked")
public AuthenticationResponse apply(HttpResponse from) {
releasePayload(from);
- Builder<String, URI> builder = ImmutableMap.builder();
- for (Entry<String, String> entry : from.getHeaders().entries()) {
- if (entry.getKey().endsWith(URL_SUFFIX))
- builder.put(entry.getKey(), getURI(entry.getValue()));
+
+ // HTTP headers are case in-sensitive (RFC 2616) so we must allow for that when looking an header names for the URL keyword
+ //FIXME When Apache commons-collections 4 is out of Snapshot it will provide generics for CaseInsensitiveMap
+ final CaseInsensitiveMap services = new CaseInsensitiveMap();
+ for (final Entry<String, String> entry : from.getHeaders().entries()) {
+ if (entry.getKey().toLowerCase().endsWith(URL_SUFFIX.toLowerCase()))
+ services.put(entry.getKey(), getURI(entry.getValue()));
}
AuthenticationResponse response = new AuthenticationResponse(checkNotNull(from.getFirstHeaderOrNull(AUTH_TOKEN),
- AUTH_TOKEN), builder.build());
+ AUTH_TOKEN), services);
logger.debug("will connect to: ", response);
return response;
}