Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1623)

Unified Diff: net/base/net_util.cc

Issue 6711046: Add an opt-out header for HTTP throttling. Never throttle for localhost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head. Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/net_util.cc
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index a850eb8b9031edb1bf495695d9a9819ed9a8fa90..959ee29a50cb73bb68b1afb11f2688a7aab47396 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -2111,6 +2111,40 @@ int GetPortFromSockaddr(const struct sockaddr* address, socklen_t address_len) {
return ntohs(*port_field);
}
+bool IsLocalhost(const std::string& host) {
+ if (host == "localhost" ||
+ host == "localhost.localdomain" ||
+ host == "localhost6" ||
+ host == "localhost6.localdomain6")
+ return true;
+
+ IPAddressNumber ip_number;
+ if (ParseIPLiteralToNumber(host, &ip_number)) {
+ size_t size = ip_number.size();
+ switch (size) {
+ case kIPv4AddressSize: {
+ IPAddressNumber localhost_prefix;
+ localhost_prefix.push_back(127);
+ for (int i = 0; i < 3; ++i) {
+ localhost_prefix.push_back(0);
+ }
+ return IPNumberMatchesPrefix(ip_number, localhost_prefix, 8);
+ }
+
+ case kIPv6AddressSize: {
+ struct in6_addr sin6_addr;
+ memcpy(&sin6_addr, &ip_number[0], kIPv6AddressSize);
+ return IN6_IS_ADDR_LOOPBACK(&sin6_addr) != FALSE;
wtc 2011/03/28 22:08:19 The != FALSE part should be unnecessary. I know w
+ }
+
+ default:
+ NOTREACHED();
+ }
+ }
+
+ return false;
+}
+
NetworkInterface::NetworkInterface() {
}
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698