mirror of https://github.com/apache/jclouds.git
Issue 451: fix redirection handler
This commit is contained in:
parent
f1b4b67a88
commit
7b5d0af43d
|
@ -76,26 +76,20 @@ public class RedirectionRetryHandler implements HttpRetryHandler {
|
||||||
if (redirectionUrl.equals(currentRequest.getEndpoint()))
|
if (redirectionUrl.equals(currentRequest.getEndpoint()))
|
||||||
return backoffHandler.shouldRetryRequest(command, response);
|
return backoffHandler.shouldRetryRequest(command, response);
|
||||||
|
|
||||||
UriBuilder builder = uriBuilderProvider.get().uri(currentRequest.getEndpoint());
|
|
||||||
assert redirectionUrl.getPath() != null : "no path in redirect header from: " + response;
|
assert redirectionUrl.getPath() != null : "no path in redirect header from: " + response;
|
||||||
|
if (!redirectionUrl.isAbsolute()) {
|
||||||
|
UriBuilder builder = uriBuilderProvider.get().uri(currentRequest.getEndpoint());
|
||||||
builder.replacePath(redirectionUrl.getPath());
|
builder.replacePath(redirectionUrl.getPath());
|
||||||
|
|
||||||
if (redirectionUrl.getScheme() != null)
|
|
||||||
builder.scheme(redirectionUrl.getScheme());
|
|
||||||
if (redirectionUrl.getPort() != currentRequest.getEndpoint().getPort())
|
|
||||||
builder.port(redirectionUrl.getPort());
|
|
||||||
if (redirectionUrl.getQuery() != null)
|
if (redirectionUrl.getQuery() != null)
|
||||||
builder.replaceQuery(redirectionUrl.getQuery());
|
builder.replaceQuery(redirectionUrl.getQuery());
|
||||||
|
redirectionUrl = builder.build();
|
||||||
if (redirectionUrl.getHost() != null)
|
}
|
||||||
builder.host(redirectionUrl.getHost());
|
|
||||||
|
|
||||||
if (currentRequest.getFirstHeaderOrNull(HOST) != null && redirectionUrl.getHost() != null) {
|
if (currentRequest.getFirstHeaderOrNull(HOST) != null && redirectionUrl.getHost() != null) {
|
||||||
command.setCurrentRequest(ModifyRequest
|
command.setCurrentRequest(ModifyRequest.replaceHeader(currentRequest, HOST,
|
||||||
.replaceHeader(currentRequest, HOST, singletonList(redirectionUrl.getHost())).toBuilder()
|
singletonList(redirectionUrl.getHost())).toBuilder().endpoint(redirectionUrl).build());
|
||||||
.endpoint(builder.build()).build());
|
|
||||||
} else {
|
} else {
|
||||||
command.setCurrentRequest(currentRequest.toBuilder().endpoint(builder.build()).build());
|
command.setCurrentRequest(currentRequest.toBuilder().endpoint(redirectionUrl).build());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue