Index: net/dns/host_resolver_impl.cc |
diff --git a/net/dns/host_resolver_impl.cc b/net/dns/host_resolver_impl.cc |
index 91475ec827a42cb2ea70a03c61cd2575ffbd13e7..abb34d845e2c6db153475aef0504c0649035a42b 100644 |
--- a/net/dns/host_resolver_impl.cc |
+++ b/net/dns/host_resolver_impl.cc |
@@ -1951,30 +1951,35 @@ bool HostResolverImpl::ServeFromHosts(const Key& key, |
if (!HaveDnsConfig()) |
return false; |
+ addresses->clear(); |
+ |
// HOSTS lookups are case-insensitive. |
std::string hostname = StringToLowerASCII(key.hostname); |
+ const DnsHosts& hosts = dns_client_->GetConfig()->hosts; |
+ |
// If |address_family| is ADDRESS_FAMILY_UNSPECIFIED other implementations |
// (glibc and c-ares) return the first matching line. We have more |
// flexibility, but lose implicit ordering. |
- // TODO(szym) http://crbug.com/117850 |
- const DnsHosts& hosts = dns_client_->GetConfig()->hosts; |
- DnsHosts::const_iterator it = hosts.find( |
- DnsHostsKey(hostname, |
- key.address_family == ADDRESS_FAMILY_UNSPECIFIED ? |
- ADDRESS_FAMILY_IPV4 : key.address_family)); |
- |
- if (it == hosts.end()) { |
- if (key.address_family != ADDRESS_FAMILY_UNSPECIFIED) |
- return false; |
+ // We prefer IPv6 because "happy eyeballs" will fall back to IPv4 if |
+ // necessary. |
+ if (key.address_family == ADDRESS_FAMILY_IPV6 || |
+ key.address_family == ADDRESS_FAMILY_UNSPECIFIED) { |
+ DnsHosts::const_iterator it = hosts.find( |
+ DnsHostsKey(hostname, ADDRESS_FAMILY_IPV6)); |
+ if (it != hosts.end()) |
+ addresses->push_back(IPEndPoint(it->second, info.port())); |
+ } |
- it = hosts.find(DnsHostsKey(hostname, ADDRESS_FAMILY_IPV6)); |
- if (it == hosts.end()) |
- return false; |
+ if (key.address_family == ADDRESS_FAMILY_IPV4 || |
+ key.address_family == ADDRESS_FAMILY_UNSPECIFIED) { |
+ DnsHosts::const_iterator it = hosts.find( |
+ DnsHostsKey(hostname, ADDRESS_FAMILY_IPV4)); |
+ if (it != hosts.end()) |
+ addresses->push_back(IPEndPoint(it->second, info.port())); |
} |
- *addresses = AddressList::CreateFromIPAddress(it->second, info.port()); |
- return true; |
+ return !addresses->empty(); |
} |
void HostResolverImpl::CacheResult(const Key& key, |