hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1603745 - in /httpcomponents/httpclient/trunk: ./ httpclient/src/main/java/org/apache/http/client/methods/ httpclient/src/main/java/org/apache/http/impl/client/ httpclient/src/main/java/org/apache/http/impl/execchain/
Date Thu, 19 Jun 2014 07:52:42 GMT
Author: olegk
Date: Thu Jun 19 07:52:41 2014
New Revision: 1603745

URL: http://svn.apache.org/r1603745
Log:
HTTPCLIENT-1519: Use the original HttpHost instance passed as a parameter to HttpClient#execute
when generating 'Host' request header

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/HttpRequestWrapper.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/ProtocolExec.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=1603745&r1=1603744&r2=1603745&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Thu Jun 19 07:52:41 2014
@@ -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>
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/HttpRequestWrapper.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/HttpRequestWrapper.java?rev=1603745&r1=1603744&r2=1603745&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/HttpRequestWrapper.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/HttpRequestWrapper.java
Thu Jun 19 07:52:41 2014
@@ -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.AbstractH
 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 
         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 
 
         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 
 
     }
 
+    /**
+     * 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);
         }
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java?rev=1603745&r1=1603744&r2=1603745&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java
Thu Jun 19 07:52:41 2014
@@ -159,7 +159,7 @@ class InternalHttpClient extends Closeab
             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;

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/ProtocolExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/ProtocolExec.java?rev=1603745&r1=1603744&r2=1603745&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/ProtocolExec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/ProtocolExec.java
Thu Jun 19 07:52:41 2014
@@ -168,6 +168,9 @@ public class ProtocolExec implements Cli
             }
         }
         if (target == null) {
+            target = request.getTarget();
+        }
+        if (target == null) {
             target = route.getTargetHost();
         }
 



Mime
View raw message