From 7fadf8b08b4aef721fb208a87edb93ad9caef966 Mon Sep 17 00:00:00 2001 From: vijaykiran Date: Fri, 1 Jun 2012 22:16:04 +0200 Subject: [PATCH] Issue-953 Make sure that port is set when modifying headers --- .../jclouds/s3/binders/BindAsHostPrefixIfConfigured.java | 6 +++++- .../org/jclouds/http/handlers/RedirectionRetryHandler.java | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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()); }