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

Side by Side Diff: net/proxy/proxy_bypass_rules.cc

Issue 602973002: Change ParseHostAndPort() to not include brackets around IPv6 literals. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a comment Created 6 years, 2 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
« no previous file with comments | « net/base/net_util_unittest.cc ('k') | net/proxy/proxy_server.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/proxy/proxy_bypass_rules.h" 5 #include "net/proxy/proxy_bypass_rules.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_piece.h"
10 #include "base/strings/string_tokenizer.h"
9 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
11 #include "base/strings/string_piece.h" 13 #include "net/base/host_port_pair.h"
12 #include "base/strings/string_tokenizer.h"
13 #include "net/base/net_util.h" 14 #include "net/base/net_util.h"
14 15
15 namespace net { 16 namespace net {
16 17
17 namespace { 18 namespace {
18 19
19 class HostnamePatternRule : public ProxyBypassRules::Rule { 20 class HostnamePatternRule : public ProxyBypassRules::Rule {
20 public: 21 public:
21 HostnamePatternRule(const std::string& optional_scheme, 22 HostnamePatternRule(const std::string& optional_scheme,
22 const std::string& hostname_pattern, 23 const std::string& hostname_pattern,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 125 }
125 126
126 private: 127 private:
127 const std::string description_; 128 const std::string description_;
128 const std::string optional_scheme_; 129 const std::string optional_scheme_;
129 const IPAddressNumber ip_prefix_; 130 const IPAddressNumber ip_prefix_;
130 const size_t prefix_length_in_bits_; 131 const size_t prefix_length_in_bits_;
131 }; 132 };
132 133
133 // Returns true if the given string represents an IP address. 134 // Returns true if the given string represents an IP address.
135 // IPv6 addresses are expected to be bracketed.
134 bool IsIPAddress(const std::string& domain) { 136 bool IsIPAddress(const std::string& domain) {
135 // From GURL::HostIsIPAddress() 137 // From GURL::HostIsIPAddress()
136 url::RawCanonOutputT<char, 128> ignored_output; 138 url::RawCanonOutputT<char, 128> ignored_output;
137 url::CanonHostInfo host_info; 139 url::CanonHostInfo host_info;
138 url::Component domain_comp(0, domain.size()); 140 url::Component domain_comp(0, domain.size());
139 url::CanonicalizeIPAddress(domain.c_str(), domain_comp, &ignored_output, 141 url::CanonicalizeIPAddress(domain.c_str(), domain_comp, &ignored_output,
140 &host_info); 142 &host_info);
141 return host_info.IsIPAddress(); 143 return host_info.IsIPAddress();
142 } 144 }
143 145
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 new BypassIPBlockRule(raw, scheme, ip_prefix, prefix_length_in_bits)); 300 new BypassIPBlockRule(raw, scheme, ip_prefix, prefix_length_in_bits));
299 301
300 return true; 302 return true;
301 } 303 }
302 304
303 // Check if we have an <ip-address>[:port] input. We need to treat this 305 // Check if we have an <ip-address>[:port] input. We need to treat this
304 // separately since the IP literal may not be in a canonical form. 306 // separately since the IP literal may not be in a canonical form.
305 std::string host; 307 std::string host;
306 int port; 308 int port;
307 if (ParseHostAndPort(raw, &host, &port)) { 309 if (ParseHostAndPort(raw, &host, &port)) {
308 if (IsIPAddress(host)) { 310 // Note that HostPortPair is used to merely to convert any IPv6 literals to
311 // a URL-safe format that can be used by canonicalization below.
312 std::string bracketed_host = HostPortPair(host, 80).HostForURL();
313 if (IsIPAddress(bracketed_host)) {
309 // Canonicalize the IP literal before adding it as a string pattern. 314 // Canonicalize the IP literal before adding it as a string pattern.
310 GURL tmp_url("http://" + host); 315 GURL tmp_url("http://" + bracketed_host);
311 return AddRuleForHostname(scheme, tmp_url.host(), port); 316 return AddRuleForHostname(scheme, tmp_url.host(), port);
312 } 317 }
313 } 318 }
314 319
315 // Otherwise assume we have <hostname-pattern>[:port]. 320 // Otherwise assume we have <hostname-pattern>[:port].
316 std::string::size_type pos_colon = raw.rfind(':'); 321 std::string::size_type pos_colon = raw.rfind(':');
317 host = raw; 322 host = raw;
318 port = -1; 323 port = -1;
319 if (pos_colon != std::string::npos) { 324 if (pos_colon != std::string::npos) {
320 if (!base::StringToInt(base::StringPiece(raw.begin() + pos_colon + 1, 325 if (!base::StringToInt(base::StringPiece(raw.begin() + pos_colon + 1,
(...skipping 18 matching lines...) Expand all
339 return AddRuleForHostname(scheme, raw, port); 344 return AddRuleForHostname(scheme, raw, port);
340 } 345 }
341 346
342 bool ProxyBypassRules::AddRuleFromStringInternalWithLogging( 347 bool ProxyBypassRules::AddRuleFromStringInternalWithLogging(
343 const std::string& raw, 348 const std::string& raw,
344 bool use_hostname_suffix_matching) { 349 bool use_hostname_suffix_matching) {
345 return AddRuleFromStringInternal(raw, use_hostname_suffix_matching); 350 return AddRuleFromStringInternal(raw, use_hostname_suffix_matching);
346 } 351 }
347 352
348 } // namespace net 353 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_util_unittest.cc ('k') | net/proxy/proxy_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698