You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ab...@apache.org on 2025/01/06 13:42:32 UTC
(httpcomponents-client) branch master updated: Normalize IDN hostnames to punycode before DNS resolution to prevent UnknownHostException during connection. (#608)
This is an automated email from the ASF dual-hosted git repository.
abernal pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git
The following commit(s) were added to refs/heads/master by this push:
new 3c82807ad Normalize IDN hostnames to punycode before DNS resolution to prevent UnknownHostException during connection. (#608)
3c82807ad is described below
commit 3c82807ad8e36f8a416bdb2dd91113138a446f0b
Author: Arturo Bernal <ab...@apache.org>
AuthorDate: Mon Jan 6 14:42:26 2025 +0100
Normalize IDN hostnames to punycode before DNS resolution to prevent UnknownHostException during connection. (#608)
---
.../apache/hc/client5/http/SystemDefaultDnsResolver.java | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
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 6a4d29357..0b27fbd7c 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,9 +26,12 @@
*/
package org.apache.hc.client5.http;
+import java.net.IDN;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import org.apache.hc.core5.util.TextUtils;
+
/**
* DNS resolver that uses the default OS implementation for resolving host names.
*
@@ -44,8 +47,18 @@ public class SystemDefaultDnsResolver implements DnsResolver {
@Override
public InetAddress[] resolve(final String host) throws UnknownHostException {
try {
+ String normalizedHost;
+ if (TextUtils.isAllASCII(host)) {
+ normalizedHost = host;
+ } else {
+ try {
+ normalizedHost = IDN.toASCII(host);
+ } catch (final IllegalArgumentException e) {
+ normalizedHost = host; // Fall back to original hostname
+ }
+ }
// 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;