Skip to content

Commit

Permalink
Work-around for HTTPCLIENT-1051
Browse files Browse the repository at this point in the history
  • Loading branch information
ok2c committed Jul 29, 2011
1 parent 0a9b529 commit 09cea95
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ since release 4.1.1.
do not correctly handle content streaming.
Contributed by James Abley <james.abley at gmail.com>

* [HTTPCLIENT-1051] Avoid reverse DNS lookups when opening SSL connections by IP address.
Contributed by Oleg Kalnichevski <olegk at apache.org>

Release 4.1.1
-------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,17 +376,25 @@ public Socket connectSocket(
} catch (SocketTimeoutException ex) {
throw new ConnectTimeoutException("Connect to " + remoteAddress + " timed out");
}

// HttpInetSocketAddress#toString() returns original hostname value of the remote address
String hostname = remoteAddress.toString();
int port = remoteAddress.getPort();
String s = ":" + port;
if (hostname.endsWith(s)) {
hostname = hostname.substring(0, hostname.length() - s.length());
}

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, port, true);
}
if (this.hostnameVerifier != null) {
try {
this.hostnameVerifier.verify(remoteAddress.getHostName(), sslsock);
this.hostnameVerifier.verify(hostname, sslsock);
// verifyHostName() didn't blowup - good!
} catch (IOException iox) {
// close the socket before re-throwing the exception
Expand Down

0 comments on commit 09cea95

Please sign in to comment.