Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,16 @@ private Connection(ConnectionManager mgr, String host, @Nullable SSLProvider ssl
this.proxySSLProvider = proxySSLProvider;
}

public boolean isSame(String host, int port) {
return socket != null && host.equals(this.host) && port == socket.getPort();
}
public boolean isSame(String host, int port) {
if (socket == null || port != socket.getPort()) return false;
try {
InetAddress target = InetAddress.getByName(host);
InetAddress remote = ((InetSocketAddress) socket.getRemoteSocketAddress()).getAddress();
return target.equals(remote) || (target.isLoopbackAddress() && remote.isLoopbackAddress());
} catch (UnknownHostException e) {
return host.equals(this.host);
}
}

public void close() throws IOException {
if (socket == null)
Expand Down