From bde2bcba2bef9e1e1d75244c25499e7c86398ec0 Mon Sep 17 00:00:00 2001 From: David Kocher Date: Tue, 17 May 2022 10:20:12 +0200 Subject: [PATCH] Register custom DNS resolver to handle IPv6 preference. --- .../core/http/CustomDnsResolver.java | 40 +++++++++++++++++++ .../core/http/HttpConnectionPoolBuilder.java | 1 + 2 files changed, 41 insertions(+) create mode 100644 core/src/main/java/ch/cyberduck/core/http/CustomDnsResolver.java diff --git a/core/src/main/java/ch/cyberduck/core/http/CustomDnsResolver.java b/core/src/main/java/ch/cyberduck/core/http/CustomDnsResolver.java new file mode 100644 index 00000000000..1e47843b7f5 --- /dev/null +++ b/core/src/main/java/ch/cyberduck/core/http/CustomDnsResolver.java @@ -0,0 +1,40 @@ +package ch.cyberduck.core.http; + +/* + * Copyright (c) 2002-2022 iterate GmbH. All rights reserved. + * https://cyberduck.io/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +import ch.cyberduck.core.DisabledCancelCallback; +import ch.cyberduck.core.Resolver; +import ch.cyberduck.core.exception.ResolveCanceledException; +import ch.cyberduck.core.exception.ResolveFailedException; +import org.apache.http.conn.DnsResolver; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +public class CustomDnsResolver implements DnsResolver { + + private final Resolver resolver = new Resolver(); + + @Override + public InetAddress[] resolve(String host) throws UnknownHostException { + try { + return new InetAddress[]{resolver.resolve(host, new DisabledCancelCallback())}; + } + catch(ResolveFailedException | ResolveCanceledException e) { + throw new UnknownHostException(e.getDetail(false)); + } + } +} diff --git a/core/src/main/java/ch/cyberduck/core/http/HttpConnectionPoolBuilder.java b/core/src/main/java/ch/cyberduck/core/http/HttpConnectionPoolBuilder.java index 0a62a0130ab..a3201f78b6f 100644 --- a/core/src/main/java/ch/cyberduck/core/http/HttpConnectionPoolBuilder.java +++ b/core/src/main/java/ch/cyberduck/core/http/HttpConnectionPoolBuilder.java @@ -180,6 +180,7 @@ public HttpClientBuilder build(final Proxy proxy, final TranscriptListener liste new BackportWindowsNegotiateSchemeFactory(null) : new SPNegoSchemeFactory()) .register(AuthSchemes.KERBEROS, new KerberosSchemeFactory()).build()); + configuration.setDnsResolver(new CustomDnsResolver()); return configuration; }