diff --git a/apis/s3/src/main/java/org/jclouds/s3/binders/BindAsHostPrefixIfConfigured.java b/apis/s3/src/main/java/org/jclouds/s3/binders/BindAsHostPrefixIfConfigured.java index d5675e8dba..321910f564 100644 --- a/apis/s3/src/main/java/org/jclouds/s3/binders/BindAsHostPrefixIfConfigured.java +++ b/apis/s3/src/main/java/org/jclouds/s3/binders/BindAsHostPrefixIfConfigured.java @@ -65,7 +65,11 @@ public class BindAsHostPrefixIfConfigured implements Binder { public R bindToRequest(R request, Object payload) { if (isVhostStyle) { request = bindAsHostPrefix.bindToRequest(request, payload); - return ModifyRequest.replaceHeader(request, HttpHeaders.HOST, request.getEndpoint().getHost()); + String host = request.getEndpoint().getHost(); + if (request.getEndpoint().getPort() != -1) { + host += ":" + request.getEndpoint().getPort(); + } + return ModifyRequest.replaceHeader(request, HttpHeaders.HOST, host); } else { UriBuilder builder = uriBuilderProvider.get().uri(request.getEndpoint()); StringBuilder path = new StringBuilder(Strings2.urlEncode(request.getEndpoint().getPath(), S3AsyncClient.class diff --git a/core/src/main/java/org/jclouds/http/handlers/RedirectionRetryHandler.java b/core/src/main/java/org/jclouds/http/handlers/RedirectionRetryHandler.java index 1966bc3a80..566e7092ef 100644 --- a/core/src/main/java/org/jclouds/http/handlers/RedirectionRetryHandler.java +++ b/core/src/main/java/org/jclouds/http/handlers/RedirectionRetryHandler.java @@ -85,8 +85,12 @@ public class RedirectionRetryHandler implements HttpRetryHandler { } if (currentRequest.getFirstHeaderOrNull(HOST) != null && redirectionUrl.getHost() != null) { + String host = redirectionUrl.getHost(); + if (redirectionUrl.getPort() != -1) { + host += ":" + redirectionUrl.getPort(); + } command.setCurrentRequest(ModifyRequest.replaceHeader(currentRequest, HOST, - singletonList(redirectionUrl.getHost())).toBuilder().endpoint(redirectionUrl).build()); + singletonList(host)).toBuilder().endpoint(redirectionUrl).build()); } else { command.setCurrentRequest(currentRequest.toBuilder().endpoint(redirectionUrl).build()); }