hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1724316 - in /httpcomponents/httpclient/trunk/httpclient/src: main/java/org/apache/http/conn/routing/HttpRoute.java test/java/org/apache/http/conn/routing/TestHttpRoute.java
Date Tue, 12 Jan 2016 20:44:19 GMT
Author: olegk
Date: Tue Jan 12 20:44:19 2016
New Revision: 1724316

URL: http://svn.apache.org/viewvc?rev=1724316&view=rev
Log:
HTTPCLIENT-1575: route target port must be non negative

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/routing/HttpRoute.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/routing/TestHttpRoute.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/routing/HttpRoute.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/routing/HttpRoute.java?rev=1724316&r1=1724315&r2=1724316&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/routing/HttpRoute.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/routing/HttpRoute.java
Tue Jan 12 20:44:19 2016
@@ -68,10 +68,11 @@ public final class HttpRoute implements
     /** Whether the route is (supposed to be) secure. */
     private final boolean secure;
 
-    private HttpRoute(final HttpHost target, final InetAddress local, final List<HttpHost>
proxies,
+    private HttpRoute(final HttpHost targetHost, final InetAddress local, final List<HttpHost>
proxies,
                      final boolean secure, final TunnelType tunnelled, final LayerType layered)
{
-        Args.notNull(target, "Target host");
-        this.targetHost = normalize(target);
+        Args.notNull(targetHost, "Target host");
+        Args.notNegative(targetHost.getPort(), "Target port");
+        this.targetHost = targetHost;
         this.localAddress = local;
         if (proxies != null && !proxies.isEmpty()) {
             this.proxyChain = new ArrayList<>(proxies);
@@ -86,34 +87,6 @@ public final class HttpRoute implements
         this.layered      = layered != null ? layered : LayerType.PLAIN;
     }
 
-    //TODO: to be removed in 5.0
-    private static int getDefaultPort(final String schemeName) {
-        if ("http".equalsIgnoreCase(schemeName)) {
-            return 80;
-        } else if ("https".equalsIgnoreCase(schemeName)) {
-            return 443;
-        } else {
-            return -1;
-        }
-
-    }
-
-    //TODO: to be removed in 5.0
-    private static HttpHost normalize(final HttpHost target) {
-        if (target.getPort() >= 0 ) {
-            return target;
-        } else {
-            final InetAddress address = target.getAddress();
-            final String schemeName = target.getSchemeName();
-            if (address != null) {
-                return new HttpHost(address, getDefaultPort(schemeName), schemeName);
-            } else {
-                final String hostName = target.getHostName();
-                return new HttpHost(hostName, getDefaultPort(schemeName), schemeName);
-            }
-        }
-    }
-
     /**
      * Creates a new route with all attributes specified explicitly.
      *

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/routing/TestHttpRoute.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/routing/TestHttpRoute.java?rev=1724316&r1=1724315&r2=1724316&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/routing/TestHttpRoute.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/routing/TestHttpRoute.java
Tue Jan 12 20:44:19 2016
@@ -577,48 +577,4 @@ public class TestHttpRoute {
         Assert.assertEquals("route was modified", route3, route1);
     }
 
-    @Test
-    public void testTargetHostNormalizationHttp() {
-        final HttpHost target = new HttpHost("somehost", -1, "http");
-        final HttpRoute route = new HttpRoute(target);
-        final HttpHost targetHost = route.getTargetHost();
-        Assert.assertEquals("somehost", targetHost.getHostName());
-        Assert.assertEquals(80, targetHost.getPort());
-        Assert.assertEquals("http", targetHost.getSchemeName());
-        Assert.assertEquals(null, targetHost.getAddress());
-    }
-
-    @Test
-    public void testTargetHostNormalizationHttps() {
-        final HttpHost target = new HttpHost("somehost", -1, "https");
-        final HttpRoute route = new HttpRoute(target);
-        final HttpHost targetHost = route.getTargetHost();
-        Assert.assertEquals("somehost", targetHost.getHostName());
-        Assert.assertEquals(443, targetHost.getPort());
-        Assert.assertEquals("https", targetHost.getSchemeName());
-        Assert.assertEquals(null, targetHost.getAddress());
-    }
-
-    @Test
-    public void testTargetHostNormalizationUnknownPorotocol() {
-        final HttpHost target = new HttpHost("somehost", -1, "blah");
-        final HttpRoute route = new HttpRoute(target);
-        final HttpHost targetHost = route.getTargetHost();
-        Assert.assertEquals("somehost", targetHost.getHostName());
-        Assert.assertEquals(-1, targetHost.getPort());
-        Assert.assertEquals("blah", targetHost.getSchemeName());
-        Assert.assertEquals(null, targetHost.getAddress());
-    }
-
-    @Test
-    public void testTargetHostNormalizationAddress() throws Exception {
-        final InetAddress address = InetAddress.getByAddress(new byte[]{127, 0, 0, 1});
-        final HttpHost target = new HttpHost(address, -1, "http");
-        final HttpRoute route = new HttpRoute(target);
-        final HttpHost targetHost = route.getTargetHost();
-        Assert.assertEquals(80, targetHost.getPort());
-        Assert.assertEquals("http", targetHost.getSchemeName());
-        Assert.assertEquals(address, targetHost.getAddress());
-    }
-
 }



Mime
View raw message