mirror of https://github.com/apache/jclouds.git
JCLOUDS-155: Making header handling in OpenStack case-insensitive
Submitted by Rodney Beede
This commit is contained in:
parent
bf723a8649
commit
375cb2075d
|
@ -56,9 +56,11 @@ public class ParseAuthenticationResponseFromHeaders implements Function<HttpResp
|
|||
*/
|
||||
public AuthenticationResponse apply(HttpResponse from) {
|
||||
releasePayload(from);
|
||||
|
||||
// HTTP headers are case insensitive (RFC 2616) so we must allow for that when looking an header names for the URL keyword
|
||||
Builder<String, URI> builder = ImmutableMap.builder();
|
||||
for (Entry<String, String> entry : from.getHeaders().entries()) {
|
||||
if (entry.getKey().endsWith(URL_SUFFIX))
|
||||
if (entry.getKey().toLowerCase().endsWith(URL_SUFFIX.toLowerCase()))
|
||||
builder.put(entry.getKey(), getURI(entry.getValue()));
|
||||
}
|
||||
AuthenticationResponse response = new AuthenticationResponse(checkNotNull(from.getFirstHeaderOrNull(AUTH_TOKEN),
|
||||
|
|
|
@ -21,7 +21,6 @@ import static org.testng.Assert.assertEquals;
|
|||
import java.net.URI;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.blobstore.reference.BlobStoreConstants;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.openstack.domain.AuthenticationResponse;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -33,7 +32,7 @@ import com.google.inject.Injector;
|
|||
import com.google.inject.name.Names;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ParseContainerListFromJsonResponse}
|
||||
* Tests behavior of {@code ParseAuthenticationResponseFromHeaders}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
|
@ -44,7 +43,6 @@ public class ParseAuthenticationResponseFromHeadersTest {
|
|||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bindConstant().annotatedWith(Names.named(BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX)).to("sdf");
|
||||
bindConstant().annotatedWith(Names.named(Constants.PROPERTY_API_VERSION)).to("1");
|
||||
}
|
||||
|
||||
|
@ -60,7 +58,20 @@ 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
|
||||
.create("http://fooman:8080/v1/token"))));
|
||||
assertEquals(md, new AuthenticationResponse("token", ImmutableMap.<String, URI> of("X-Storage-Url",
|
||||
URI.create("http://fooman:8080/v1/token"))));
|
||||
}
|
||||
|
||||
public void testHandleHeadersCaseInsensitively() {
|
||||
ParseAuthenticationResponseFromHeaders parser = i.getInstance(ParseAuthenticationResponseFromHeaders.class);
|
||||
parser = parser.setHostToReplace("fooman");
|
||||
|
||||
HttpResponse response = HttpResponse.builder().statusCode(204).message("No Content")
|
||||
.addHeader("x-auth-token", "token")
|
||||
.addHeader("x-storage-token", "token")
|
||||
.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.create("http://fooman:8080/v1/token"))));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue