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

Side by Side 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 lkgr 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/base/net_util.h" 5 #include "net/base/net_util.h"
6 6
7 #include <unicode/regex.h> 7 #include <unicode/regex.h>
8 #include <unicode/ucnv.h> 8 #include <unicode/ucnv.h>
9 #include <unicode/uidna.h> 9 #include <unicode/uidna.h>
10 #include <unicode/ulocdata.h> 10 #include <unicode/ulocdata.h>
(...skipping 2093 matching lines...) Expand 10 before | Expand all | Expand 10 after
2104 } 2104 }
2105 } 2105 }
2106 2106
2107 int GetPortFromSockaddr(const struct sockaddr* address, socklen_t address_len) { 2107 int GetPortFromSockaddr(const struct sockaddr* address, socklen_t address_len) {
2108 const uint16* port_field = GetPortFieldFromSockaddr(address, address_len); 2108 const uint16* port_field = GetPortFieldFromSockaddr(address, address_len);
2109 if (!port_field) 2109 if (!port_field)
2110 return -1; 2110 return -1;
2111 return ntohs(*port_field); 2111 return ntohs(*port_field);
2112 } 2112 }
2113 2113
2114 bool IsLocalhost(const std::string& host) {
2115 if (host == "localhost" ||
2116 host == "localhost.localdomain" ||
2117 host == "localhost6" ||
2118 host == "localhost6.localdomain6")
yzshen1 2011/03/24 20:06:37 [minor, optional] might be good to change the comm
Jói 2011/03/24 22:03:45 Done.
2119 return true;
2120
2121 IPAddressNumber ip_number;
2122 if (ParseIPLiteralToNumber(host, &ip_number)) {
2123 size_t size = ip_number.size();
2124 switch (size) {
2125 case kIPv4AddressSize: {
2126 IPAddressNumber localhost_prefix;
2127 localhost_prefix.push_back(127);
2128 for (int i = 0; i < 3; ++i) {
2129 localhost_prefix.push_back(0);
2130 }
2131 return IPNumberMatchesPrefix(ip_number, localhost_prefix, 8);
2132 }
2133
2134 case kIPv6AddressSize: {
2135 if (ip_number[15] != 1)
2136 return false;
2137
2138 for (int i = 0; i < 15; ++i) {
2139 if (ip_number[i] != 0)
2140 return false;
2141 }
2142
2143 return true;
2144 }
2145
2146 default:
2147 NOTREACHED();
2148 }
2149 }
2150
2151 return false;
2152 }
2153
2114 NetworkInterface::NetworkInterface() { 2154 NetworkInterface::NetworkInterface() {
2115 } 2155 }
2116 2156
2117 NetworkInterface::NetworkInterface(const std::string& name, 2157 NetworkInterface::NetworkInterface(const std::string& name,
2118 const IPAddressNumber& address) 2158 const IPAddressNumber& address)
2119 : name(name), address(address) { 2159 : name(name), address(address) {
2120 } 2160 }
2121 2161
2122 NetworkInterface::~NetworkInterface() { 2162 NetworkInterface::~NetworkInterface() {
2123 } 2163 }
2124 2164
2125 } // namespace net 2165 } // namespace net
OLDNEW
« 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