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

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: Respond to review comments. 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
Index: net/base/net_util.cc
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 1a8aa8962ffac5393f49848a33a0db768100ef46..4ed2e528e605feaff218533c261806f8023fad52 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -2111,6 +2111,46 @@ 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: {
wtc 2011/03/25 19:06:24 Thank you for considering the byte order issue. W
Jói 2011/03/25 21:26:51 Done.
+ if (ip_number[15] != 1)
+ return false;
+
+ for (int i = 0; i < 15; ++i) {
+ if (ip_number[i] != 0)
+ return false;
+ }
+
+ return true;
+ }
+
+ default:
+ NOTREACHED();
+ }
+ }
+
+ return false;
+}
+
NetworkInterface::NetworkInterface() {
}

Powered by Google App Engine
This is Rietveld 408576698