File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
httpclient5/src/main/java/org/apache/hc/client5/http Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 2626 */
2727package org .apache .hc .client5 .http ;
2828
29+ import java .net .IDN ;
2930import java .net .InetAddress ;
3031import java .net .UnknownHostException ;
3132
33+ import org .apache .hc .core5 .util .TextUtils ;
34+
3235/**
3336 * DNS resolver that uses the default OS implementation for resolving host names.
3437 *
@@ -44,8 +47,18 @@ public class SystemDefaultDnsResolver implements DnsResolver {
4447 @ Override
4548 public InetAddress [] resolve (final String host ) throws UnknownHostException {
4649 try {
50+ String normalizedHost ;
51+ if (TextUtils .isAllASCII (host )) {
52+ normalizedHost = host ;
53+ } else {
54+ try {
55+ normalizedHost = IDN .toASCII (host );
56+ } catch (final IllegalArgumentException e ) {
57+ normalizedHost = host ; // Fall back to original hostname
58+ }
59+ }
4760 // Try resolving using the default resolver
48- return InetAddress .getAllByName (host );
61+ return InetAddress .getAllByName (normalizedHost );
4962 } catch (final UnknownHostException e ) {
5063 // If default resolver fails, try stripping the IPv6 zone ID and resolving again
5164 String strippedHost = null ;
You can’t perform that action at this time.
0 commit comments