Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;
Expand Down
Loading