hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1431285 - /httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
Date Thu, 10 Jan 2013 11:27:36 GMT
Author: kwright
Date: Thu Jan 10 11:27:36 2013
New Revision: 1431285

URL: http://svn.apache.org/viewvc?rev=1431285&view=rev
Log:
Second fix for HTTPCLIENT-1296.  Include Oleg's suggestions as to a better way to obtain a
port from the non-existent target.

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java?rev=1431285&r1=1431284&r2=1431285&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
Thu Jan 10 11:27:36 2013
@@ -380,6 +380,15 @@ public class DefaultRequestDirector impl
 
         virtualHost = (HttpHost) origWrapper.getParams().getParameter(ClientPNames.VIRTUAL_HOST);
 
+        // HTTPCLIENT-1092 - add the port if necessary
+        if (virtualHost != null && virtualHost.getPort() == -1) {
+            HttpHost host = (target != null) ? target : origRoute.getTargetHost();
+            int port = host.getPort();
+            if (port != -1){
+                virtualHost = new HttpHost(virtualHost.getHostName(), port, virtualHost.getSchemeName());
+            }
+        }
+
         RoutedRequest roureq = new RoutedRequest(origWrapper, origRoute);
 
         boolean reuse = false;
@@ -449,27 +458,19 @@ public class DefaultRequestDirector impl
                 }
 
                 // Get target.  Even if there's virtual host, we may need the target to set
the port.
-                URI requestURI = wrapper.getURI();
-                if (requestURI.isAbsolute()) {
-                    target = new HttpHost(
-                        requestURI.getHost(), requestURI.getPort(), requestURI.getScheme());
+                if (virtualHost != null) {
+                    target = virtualHost;
+                } else {
+                    URI requestURI = wrapper.getURI();
+                    if (requestURI.isAbsolute()) {
+                        target = new HttpHost(
+                            requestURI.getHost(), requestURI.getPort(), requestURI.getScheme());
+                    }
                 }
                 if (target == null) {
                     target = route.getTargetHost();
                 }
 
-                // Override the target if the virtual host is present.  But make sure the
port is right.
-                if (virtualHost != null) {
-                    // HTTPCLIENT-1092 - add the port if necessary
-                    if (virtualHost.getPort() == -1 && target != null) {
-                        int port = target.getPort();
-                        if (port != -1) {
-                            virtualHost = new HttpHost(virtualHost.getHostName(), port, virtualHost.getSchemeName());
-                        }
-                    }
-                    target = virtualHost;
-                }
-
                 // Reset headers on the request wrapper
                 wrapper.resetHeaders();
                 // Re-write request URI if needed



Mime
View raw message