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

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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 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>
11 #include <unicode/uniset.h> 11 #include <unicode/uniset.h>
(...skipping 2092 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")
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.
2116 return true;
2117
2118 IPAddressNumber ip_number;
2119 if (ParseIPLiteralToNumber(host, &ip_number)) {
2120 size_t size = ip_number.size();
2121 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.
2122 IPAddressNumber localhost_prefix;
2123 localhost_prefix.push_back(127);
2124 for (int i = 0; i < 3; ++i) {
2125 localhost_prefix.push_back(0);
2126 }
2127 return IPNumberMatchesPrefix(ip_number, localhost_prefix, 8);
2128 } else if (size == 16) {
2129 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
2130 return false;
2131
2132 for (int i = 0; i < 15; ++i) {
2133 if (ip_number[i] != 0)
2134 return false;
2135 }
2136
2137 return true;
2138 } else {
2139 NOTREACHED();
2140 }
2141 }
2142
2143 return false;
2144 }
2145
2114 } // namespace net 2146 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698