summaryrefslogtreecommitdiffstats
path: root/net/base/net_util.cc
diff options
context:
space:
mode:
authorjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-25 22:30:21 +0000
committerjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-25 22:30:21 +0000
commit2fd33ee9acea0037b010901af1601616c21cc37d (patch)
tree9109f46ae1e4efe4ec8d345853064113e6379915 /net/base/net_util.cc
parent49a9415f1fd04e05c2d75e884a0aced8e0d76063 (diff)
downloadchromium_src-2fd33ee9acea0037b010901af1601616c21cc37d.zip
chromium_src-2fd33ee9acea0037b010901af1601616c21cc37d.tar.gz
chromium_src-2fd33ee9acea0037b010901af1601616c21cc37d.tar.bz2
Add an opt-out header for HTTP throttling. Never throttle for localhost.
Added net::IsLocalhost() function to net/base/net_utils.h Unit tests for the above. Also fix flakiness in the ReceivedContentMalformed test that was caused by non-zero jitter. Modify back-off policy to ignore first 4 errors to help avoid back-off from erroneously kicking in on flaky connections. Make maximum back-off period 15 minutes instead of 60. Added documentation of results of analyzing behavior this new policy will give. Add a simple server for manual testing of the throttling feature. BUG=66062 TEST=net_unittests Review URL: http://codereview.chromium.org/6711046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79464 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/net_util.cc')
-rw-r--r--net/base/net_util.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index a850eb8..959ee29 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;
+ }
+
+ default:
+ NOTREACHED();
+ }
+ }
+
+ return false;
+}
+
NetworkInterface::NetworkInterface() {
}