Commit fbcdfcda authored by Matt Menke's avatar Matt Menke Committed by Commit Bot

Make HostStringIsLocalhost() call IPAddress::IsLoopback().

Currently, they do the same thing for numeric IPs (modulo a DCHECK
that the IP is valid in HostStringIsLocalhost()), but I don't think we
want the two methods to have potentially divergent concept of loopback
IPs if, for instance, we add IPv6-mapped IPv4 loopback addresses.

Bug: None
Change-Id: Ia193c2dff08f90bf62847a89fb6b31f130f75fa7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1739482Reviewed-by: default avatarEric Roman <eroman@chromium.org>
Commit-Queue: Matt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684452}
parent 0c9f843f
...@@ -356,27 +356,10 @@ bool IsLocalhost(const GURL& url) { ...@@ -356,27 +356,10 @@ bool IsLocalhost(const GURL& url) {
} }
bool HostStringIsLocalhost(base::StringPiece host) { bool HostStringIsLocalhost(base::StringPiece host) {
if (IsLocalHostname(host, nullptr))
return true;
IPAddress ip_address; IPAddress ip_address;
if (ip_address.AssignFromIPLiteral(host)) { if (ip_address.AssignFromIPLiteral(host))
size_t size = ip_address.size(); return ip_address.IsLoopback();
switch (size) { return IsLocalHostname(host, nullptr);
case IPAddress::kIPv4AddressSize: {
const uint8_t prefix[] = {127};
return IPAddressStartsWith(ip_address, prefix);
}
case IPAddress::kIPv6AddressSize:
return ip_address == IPAddress::IPv6Localhost();
default:
NOTREACHED();
}
}
return false;
} }
GURL SimplifyUrlForRequest(const GURL& url) { GURL SimplifyUrlForRequest(const GURL& url) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment