Permalink
Browse files

Only resolve hostname if not using a SOCKS proxy (PR #774)

  • Loading branch information...
jkutner authored and vlsi committed Mar 9, 2017
1 parent f375701 commit 480b0cf1ffe266e41e259f1f7a016d3ea681cc3a
Showing with 7 additions and 1 deletion.
  1. +7 −1 pgjdbc/src/main/java/org/postgresql/core/PGStream.java
@@ -59,7 +59,13 @@ public PGStream(SocketFactory socketFactory, HostSpec hostSpec, int timeout) thr
Socket socket = socketFactory.createSocket();
if (!socket.isConnected()) {
socket.connect(new InetSocketAddress(hostSpec.getHost(), hostSpec.getPort()), timeout);
// When using a SOCKS proxy, the host might not be resolvable locally,
// thus we defer resolution until the traffic reaches the proxy. If there
// is no proxy, we must resolve the host to an IP to connect the socket.
InetSocketAddress address = System.getProperty("socksProxyHost") == null
? new InetSocketAddress(hostSpec.getHost(), hostSpec.getPort())
: InetSocketAddress.createUnresolved(hostSpec.getHost(), hostSpec.getPort());
socket.connect(address, timeout);
}
changeSocket(socket);
setEncoding(Encoding.getJVMEncoding("UTF-8"));

0 comments on commit 480b0cf

Please sign in to comment.