Issue 82: Filters didn't copy when redirects occurred

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1908 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-09-24 00:18:50 +00:00
parent 2f2dd9f881
commit 09f81b222a
1 changed files with 7 additions and 4 deletions

View File

@ -25,6 +25,7 @@ package org.jclouds.http;
import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@ -106,13 +107,15 @@ public class TransformingHttpCommandImpl<T> implements TransformingHttpCommand<T
* <p />
* This also removes the Host header in order to avoid ssl problems.
*/
public HttpRequest setHostAndPort(String host, int port) {
public HttpRequest setHostAndPort(String host, int port) { // TODO must unit test to ensure
// request is copied 100%
UriBuilder builder = UriBuilder.fromUri(request.getEndpoint());
builder.host(host);
builder.port(port);
Object oldEntity = request.getEntity();
request = new HttpRequest(request.getMethod(), builder.build(), request.getHeaders());
request.setEntity(oldEntity);
List<HttpRequestFilter> oldFilters = request.getFilters();
request = new HttpRequest(request.getMethod(), builder.build(), request.getHeaders(), request
.getEntity());
request.getFilters().addAll(oldFilters);
request.getHeaders().replaceValues(HttpHeaders.HOST, Collections.singletonList(host));
return request;
}