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

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: Update copyright years. 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 f3b01271910f21a755fe0494fdf5b0eccb646dd6..d1f870da232fcd4f6a6a0a3c189761fc6f1af73a 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -2111,4 +2111,36 @@ int GetPortFromSockaddr(const struct sockaddr* address, socklen_t address_len) {
return ntohs(*port_field);
}
+bool IsLocalhost(const std::string& host) {
+ if (host == "localhost")
wtc 2011/03/23 00:06:58 We should also check for "localhost.localdomain",
Jói 2011/03/23 23:38:24 Thanks, I was unaware of these.
+ return true;
+
+ IPAddressNumber ip_number;
+ if (ParseIPLiteralToNumber(host, &ip_number)) {
+ size_t size = ip_number.size();
+ if (size == 4) {
wtc 2011/03/23 00:06:58 Nit: we usually use a switch statement for this ki
Jói 2011/03/23 23:38:24 Done.
+ 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);
+ } else if (size == 16) {
+ if (!ip_number[15] == 1)
wtc 2011/03/23 00:06:58 BUG: this should be ip_number[15] != 1 (You sho
Jói 2011/03/23 23:38:24 Thanks, fixed that and added the test case. I cou
+ return false;
+
+ for (int i = 0; i < 15; ++i) {
+ if (ip_number[i] != 0)
+ return false;
+ }
+
+ return true;
+ } else {
+ NOTREACHED();
+ }
+ }
+
+ return false;
+}
+
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698