Use AuthoritativeDnsServerCache for creating the new redirect stream. (#8316)

* Use AuthoritativeDnsServerCache for creating the new redirect stream.

Motivation:

At the moment if a user wants to provide custom sorting of the nameservers used for redirects it needs to be implemented in two places. This is more complicated as it needs to be.

Modifications:

- Just delegate to the AuthoritativeDnsServerCache always as we fill it before we call newRedirectDnsServerStream anyway.

Result:

Easier way for the user to implement custom sorting.
This commit is contained in:
Norman Maurer 2018-09-27 19:45:58 +02:00 committed by GitHub
parent 5650db5826
commit b81c8ed55c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -450,8 +450,14 @@ public class DnsNameResolver extends InetNameResolver {
*/
protected DnsServerAddressStream newRedirectDnsServerStream(
@SuppressWarnings("unused") String hostname, List<InetSocketAddress> nameservers) {
Collections.sort(nameservers, nameServerComparator);
return new SequentialDnsServerAddressStream(nameservers, 0);
DnsServerAddressStream cached = authoritativeDnsServerCache().get(hostname);
if (cached == null || cached.size() == 0) {
// If there is no cache hit (which may be the case for example when a NoopAuthoritativeDnsServerCache
// is used), we will just directly use the provided nameservers.
Collections.sort(nameservers, nameServerComparator);
return new SequentialDnsServerAddressStream(nameservers, 0);
}
return cached;
}
/**