You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2011/07/29 22:12:31 UTC

svn commit: r1152363 - /httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java

Author: olegk
Date: Fri Jul 29 20:12:30 2011
New Revision: 1152363

URL: http://svn.apache.org/viewvc?rev=1152363&view=rev
Log:
HTTPCLIENT-1051: paranoia is fun

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java?rev=1152363&r1=1152362&r2=1152363&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java Fri Jul 29 20:12:30 2011
@@ -27,6 +27,7 @@
 
 package org.apache.http.conn.ssl;
 
+import org.apache.http.HttpHost;
 import org.apache.http.annotation.ThreadSafe;
 
 import org.apache.http.conn.ConnectTimeoutException;
@@ -381,23 +382,25 @@ public class SSLSocketFactory implements
         } catch (SocketTimeoutException ex) {
             throw new ConnectTimeoutException("Connect to " + remoteAddress + " timed out");
         }
+
+        String hostname;
+        if (remoteAddress instanceof HttpInetSocketAddress) {
+            hostname = ((HttpInetSocketAddress) remoteAddress).getHost().getHostName();
+        } else {
+            hostname = remoteAddress.getHostName();
+        }
+
         SSLSocket sslsock;
         // Setup SSL layering if necessary
         if (sock instanceof SSLSocket) {
             sslsock = (SSLSocket) sock;
         } else {
-            sslsock = (SSLSocket) this.socketfactory.createSocket(
-                    sock, remoteAddress.getHostName(), remoteAddress.getPort(), true);
+            sslsock = (SSLSocket) this.socketfactory.createSocket(sock,
+                    hostname, remoteAddress.getPort(), true);
             prepareSocket(sslsock);
         }
         if (this.hostnameVerifier != null) {
             try {
-                String hostname;
-                if (remoteAddress instanceof HttpInetSocketAddress) {
-                    hostname = ((HttpInetSocketAddress) remoteAddress).getHost().getHostName();
-                } else {
-                    hostname = remoteAddress.getHostName();
-                }
                 this.hostnameVerifier.verify(hostname, sslsock);
                 // verifyHostName() didn't blowup - good!
             } catch (IOException iox) {
@@ -496,7 +499,7 @@ public class SSLSocketFactory implements
         } else {
             remoteAddress = InetAddress.getByName(host);
         }
-        InetSocketAddress remote = new InetSocketAddress(remoteAddress, port);
+        InetSocketAddress remote = new HttpInetSocketAddress(new HttpHost(host, port), remoteAddress, port);
         return connectSocket(socket, remote, local, params);
     }