HTTPCLIENT-1519: Use the original HttpHost instance passed as a parameter to HttpClient#execute when generating 'Host' request header
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1603745 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7ae0a8ac5f
commit
ad092c5d03
|
@ -4,6 +4,10 @@ Changes for 4.4-alpha1
|
|||
Changelog:
|
||||
-------------------
|
||||
|
||||
* [HTTPCLIENT-1519] Use the original HttpHost instance passed as a parameter to
|
||||
HttpClient#execute when generating 'Host' request header.
|
||||
Contributed by Oleg Kalnichevski <olegk at apache.org>
|
||||
|
||||
* Replaced dynamic proxies with custom proxy classes to reduce thread contention.
|
||||
Contributed by Oleg Kalnichevski <olegk at apache.org>
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import java.net.URI;
|
|||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.RequestLine;
|
||||
|
@ -40,6 +41,7 @@ import org.apache.http.message.AbstractHttpMessage;
|
|||
import org.apache.http.message.BasicRequestLine;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
import org.apache.http.util.Args;
|
||||
|
||||
/**
|
||||
* A wrapper class for {@link HttpRequest} that can be used to change properties of the current
|
||||
|
@ -52,13 +54,15 @@ import org.apache.http.protocol.HTTP;
|
|||
public class HttpRequestWrapper extends AbstractHttpMessage implements HttpUriRequest {
|
||||
|
||||
private final HttpRequest original;
|
||||
private final HttpHost target;
|
||||
private final String method;
|
||||
private ProtocolVersion version;
|
||||
private URI uri;
|
||||
|
||||
private HttpRequestWrapper(final HttpRequest request) {
|
||||
private HttpRequestWrapper(final HttpRequest request, final HttpHost target) {
|
||||
super();
|
||||
this.original = request;
|
||||
this.original = Args.notNull(request, "HTTP request");
|
||||
this.target = target;
|
||||
this.version = this.original.getRequestLine().getProtocolVersion();
|
||||
this.method = this.original.getRequestLine().getMethod();
|
||||
if (request instanceof HttpUriRequest) {
|
||||
|
@ -120,6 +124,13 @@ public class HttpRequestWrapper extends AbstractHttpMessage implements HttpUriRe
|
|||
return this.original;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Since 4.4
|
||||
*/
|
||||
public HttpHost getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getRequestLine() + " " + this.headergroup;
|
||||
|
@ -130,8 +141,8 @@ public class HttpRequestWrapper extends AbstractHttpMessage implements HttpUriRe
|
|||
|
||||
private HttpEntity entity;
|
||||
|
||||
public HttpEntityEnclosingRequestWrapper(final HttpEntityEnclosingRequest request) {
|
||||
super(request);
|
||||
HttpEntityEnclosingRequestWrapper(final HttpEntityEnclosingRequest request, final HttpHost target) {
|
||||
super(request, target);
|
||||
this.entity = request.getEntity();
|
||||
}
|
||||
|
||||
|
@ -153,14 +164,31 @@ public class HttpRequestWrapper extends AbstractHttpMessage implements HttpUriRe
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a mutable wrapper of the original request.
|
||||
*
|
||||
* @param request original request
|
||||
* @return mutable request wrappering the original one
|
||||
*/
|
||||
public static HttpRequestWrapper wrap(final HttpRequest request) {
|
||||
if (request == null) {
|
||||
return null;
|
||||
return wrap(request, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a mutable wrapper of the original request.
|
||||
*
|
||||
* @param request original request
|
||||
* @param target original target, if explicitly specified
|
||||
* @return mutable request wrappering the original one
|
||||
* @since 4.4
|
||||
*/
|
||||
public static HttpRequestWrapper wrap(final HttpRequest request, final HttpHost target) {
|
||||
Args.notNull(request, "HTTP request");
|
||||
if (request instanceof HttpEntityEnclosingRequest) {
|
||||
return new HttpEntityEnclosingRequestWrapper((HttpEntityEnclosingRequest) request);
|
||||
return new HttpEntityEnclosingRequestWrapper((HttpEntityEnclosingRequest) request, target);
|
||||
} else {
|
||||
return new HttpRequestWrapper(request);
|
||||
return new HttpRequestWrapper(request, target);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -159,7 +159,7 @@ class InternalHttpClient extends CloseableHttpClient {
|
|||
execAware = (HttpExecutionAware) request;
|
||||
}
|
||||
try {
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(request);
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(request, target);
|
||||
final HttpClientContext localcontext = HttpClientContext.adapt(
|
||||
context != null ? context : new BasicHttpContext());
|
||||
RequestConfig config = null;
|
||||
|
|
|
@ -167,6 +167,9 @@ public class ProtocolExec implements ClientExecChain {
|
|||
target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
|
||||
}
|
||||
}
|
||||
if (target == null) {
|
||||
target = request.getTarget();
|
||||
}
|
||||
if (target == null) {
|
||||
target = route.getTargetHost();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue