Issue 451: fix redirection handler

This commit is contained in:
Adrian Cole 2011-01-24 18:09:35 -08:00
parent f1b4b67a88
commit 7b5d0af43d
1 changed files with 10 additions and 16 deletions

View File

@ -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;
builder.replacePath(redirectionUrl.getPath()); if (!redirectionUrl.isAbsolute()) {
UriBuilder builder = uriBuilderProvider.get().uri(currentRequest.getEndpoint());
if (redirectionUrl.getScheme() != null) builder.replacePath(redirectionUrl.getPath());
builder.scheme(redirectionUrl.getScheme()); if (redirectionUrl.getQuery() != null)
if (redirectionUrl.getPort() != currentRequest.getEndpoint().getPort()) builder.replaceQuery(redirectionUrl.getQuery());
builder.port(redirectionUrl.getPort()); redirectionUrl = builder.build();
if (redirectionUrl.getQuery() != null) }
builder.replaceQuery(redirectionUrl.getQuery());
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 {