< prev index next >

src/java.base/share/classes/java/net/HttpConnectSocketImpl.java

Print this page

        

@@ -112,18 +112,21 @@
         throws IOException
     {
         if (endpoint == null || !(endpoint instanceof InetSocketAddress))
             throw new IllegalArgumentException("Unsupported address type");
         final InetSocketAddress epoint = (InetSocketAddress)endpoint;
-        final String destHost = epoint.isUnresolved() ? epoint.getHostName()
+        String destHost = epoint.isUnresolved() ? epoint.getHostName()
                                                       : epoint.getAddress().getHostAddress();
         final int destPort = epoint.getPort();
 
         SecurityManager security = System.getSecurityManager();
         if (security != null)
             security.checkConnect(destHost, destPort);
 
+        if (destHost.contains(":"))
+            destHost = "[" + destHost + "]";
+
         // Connect to the HTTP proxy server
         String urlString = "http://" + destHost + ":" + destPort;
         Socket httpSocket = privilegedDoTunnel(urlString, timeout);
 
         // Success!
< prev index next >