diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/SystemDefaultDnsResolver.java b/httpclient5/src/main/java/org/apache/hc/client5/http/SystemDefaultDnsResolver.java index 6a4d293573..7430c9bf7b 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/SystemDefaultDnsResolver.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/SystemDefaultDnsResolver.java @@ -26,6 +26,7 @@ */ package org.apache.hc.client5.http; +import java.net.IDN; import java.net.InetAddress; import java.net.UnknownHostException; @@ -44,8 +45,9 @@ public class SystemDefaultDnsResolver implements DnsResolver { @Override public InetAddress[] resolve(final String host) throws UnknownHostException { try { + final String normalizedHost = IDN.toASCII(host); // Try resolving using the default resolver - return InetAddress.getAllByName(host); + return InetAddress.getAllByName(normalizedHost); } catch (final UnknownHostException e) { // If default resolver fails, try stripping the IPv6 zone ID and resolving again String strippedHost = null; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java index 1f20eccb6f..33a4cfcf82 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java @@ -27,12 +27,10 @@ package org.apache.hc.client5.http.impl.io; import java.io.IOException; -import java.net.IDN; import java.net.InetSocketAddress; import java.net.Proxy; import java.net.Socket; import java.net.SocketAddress; -import java.net.UnknownHostException; import java.util.Collections; import java.util.List; @@ -165,20 +163,13 @@ public void connect( final SocketAddress socksProxyAddress = socketConfig.getSocksProxyAddress(); final Proxy socksProxy = socksProxyAddress != null ? new Proxy(Proxy.Type.SOCKS, socksProxyAddress) : null; - final String normalizedHost; - try { - normalizedHost = IDN.toASCII(endpointHost.getHostName()); - } catch (final IllegalArgumentException e) { - throw new UnknownHostException("Invalid IDN hostname: " + endpointHost.getHostName()); - } - final List remoteAddresses; if (endpointHost.getAddress() != null) { remoteAddresses = Collections.singletonList( new InetSocketAddress(endpointHost.getAddress(), this.schemePortResolver.resolve(endpointHost.getSchemeName(), endpointHost))); } else { final int port = this.schemePortResolver.resolve(endpointHost.getSchemeName(), endpointHost); - remoteAddresses = this.dnsResolver.resolve(normalizedHost, port); + remoteAddresses = this.dnsResolver.resolve(endpointHost.getHostName(), port); } for (int i = 0; i < remoteAddresses.size(); i++) { final InetSocketAddress remoteAddress = remoteAddresses.get(i); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/MultihomeIOSessionRequester.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/MultihomeIOSessionRequester.java index fde1c699c8..4b8172c4ce 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/MultihomeIOSessionRequester.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/MultihomeIOSessionRequester.java @@ -28,7 +28,6 @@ package org.apache.hc.client5.http.impl.nio; import java.io.IOException; -import java.net.IDN; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; @@ -108,11 +107,10 @@ public void cancelled() { if (LOG.isDebugEnabled()) { LOG.debug("{} resolving remote address", remoteEndpoint.getHostName()); } - final String normalizedHost; + final List remoteAddresses; try { - normalizedHost = IDN.toASCII(remoteEndpoint.getHostName()); - remoteAddresses = dnsResolver.resolve(normalizedHost, remoteEndpoint.getPort()); + remoteAddresses = dnsResolver.resolve(remoteEndpoint.getHostName(), remoteEndpoint.getPort()); if (remoteAddresses == null || remoteAddresses.isEmpty()) { throw new UnknownHostException(remoteEndpoint.getHostName()); }