Chromium Code Reviews| 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..627cba8cf39c02108a070b5f72eddfcc92350987 100644 |
| --- a/net/dns/host_resolver_impl.cc |
| +++ b/net/dns/host_resolver_impl.cc |
| @@ -1954,27 +1954,33 @@ bool HostResolverImpl::ServeFromHosts(const Key& key, |
| // 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)); |
| + // We prefer IPv6 because "happy eyeballs" will fall back to IPv4 if |
| + // necessary. |
|
mmenke
2013/03/27 21:31:48
nit: May want to move this just above the IPV6 bl
|
| - if (it == hosts.end()) { |
| - if (key.address_family != ADDRESS_FAMILY_UNSPECIFIED) |
| - return false; |
| + addresses->clear(); |
| - it = hosts.find(DnsHostsKey(hostname, ADDRESS_FAMILY_IPV6)); |
| - if (it == hosts.end()) |
| - return false; |
| + 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())); |
| } |
| - *addresses = AddressList::CreateFromIPAddress(it->second, info.port()); |
| - return true; |
| + 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())); |
| + } |
| + |
| + return !addresses->empty(); |
| } |
| void HostResolverImpl::CacheResult(const Key& key, |