Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/pattern.h" | 8 #include "base/strings/pattern.h" |
| 9 #include "base/strings/string_number_conversions.h" | |
| 10 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
| 11 #include "base/strings/string_tokenizer.h" | 10 #include "base/strings/string_tokenizer.h" |
| 12 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 14 #include "net/base/host_port_pair.h" | 13 #include "net/base/host_port_pair.h" |
| 15 #include "net/base/ip_address.h" | 14 #include "net/base/ip_address.h" |
| 15 #include "net/base/parse_number.h" | |
| 16 #include "net/base/url_util.h" | 16 #include "net/base/url_util.h" |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 class HostnamePatternRule : public ProxyBypassRules::Rule { | 22 class HostnamePatternRule : public ProxyBypassRules::Rule { |
| 23 public: | 23 public: |
| 24 HostnamePatternRule(const std::string& optional_scheme, | 24 HostnamePatternRule(const std::string& optional_scheme, |
| 25 const std::string& hostname_pattern, | 25 const std::string& hostname_pattern, |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 std::string bracketed_host = HostPortPair(host, 80).HostForURL(); | 310 std::string bracketed_host = HostPortPair(host, 80).HostForURL(); |
| 311 if (IsIPAddress(bracketed_host)) { | 311 if (IsIPAddress(bracketed_host)) { |
| 312 // Canonicalize the IP literal before adding it as a string pattern. | 312 // Canonicalize the IP literal before adding it as a string pattern. |
| 313 GURL tmp_url("http://" + bracketed_host); | 313 GURL tmp_url("http://" + bracketed_host); |
| 314 return AddRuleForHostname(scheme, tmp_url.host(), port); | 314 return AddRuleForHostname(scheme, tmp_url.host(), port); |
| 315 } | 315 } |
| 316 } | 316 } |
| 317 | 317 |
| 318 // Otherwise assume we have <hostname-pattern>[:port]. | 318 // Otherwise assume we have <hostname-pattern>[:port]. |
| 319 std::string::size_type pos_colon = raw.rfind(':'); | 319 std::string::size_type pos_colon = raw.rfind(':'); |
| 320 host = raw; | |
|
eroman
2016/03/23 22:41:53
This removal is not strictly part of this change.
| |
| 321 port = -1; | 320 port = -1; |
| 322 if (pos_colon != std::string::npos) { | 321 if (pos_colon != std::string::npos) { |
| 323 if (!base::StringToInt(base::StringPiece(raw.begin() + pos_colon + 1, | 322 if (!ParseNonNegativeDecimalInt( |
| 324 raw.end()), | 323 base::StringPiece(raw.begin() + pos_colon + 1, raw.end()), &port) || |
| 325 &port) || | 324 port > 0xFFFF) { |
| 326 (port < 0 || port > 0xFFFF)) { | |
| 327 return false; // Port was invalid. | 325 return false; // Port was invalid. |
| 328 } | 326 } |
| 329 raw = raw.substr(0, pos_colon); | 327 raw = raw.substr(0, pos_colon); |
| 330 } | 328 } |
| 331 | 329 |
| 332 // Special-case hostnames that begin with a period. | 330 // Special-case hostnames that begin with a period. |
| 333 // For example, we remap ".google.com" --> "*.google.com". | 331 // For example, we remap ".google.com" --> "*.google.com". |
| 334 if (base::StartsWith(raw, ".", base::CompareCase::SENSITIVE)) | 332 if (base::StartsWith(raw, ".", base::CompareCase::SENSITIVE)) |
| 335 raw = "*" + raw; | 333 raw = "*" + raw; |
| 336 | 334 |
| 337 // If suffix matching was asked for, make sure the pattern starts with a | 335 // If suffix matching was asked for, make sure the pattern starts with a |
| 338 // wildcard. | 336 // wildcard. |
| 339 if (use_hostname_suffix_matching && | 337 if (use_hostname_suffix_matching && |
| 340 !base::StartsWith(raw, "*", base::CompareCase::SENSITIVE)) | 338 !base::StartsWith(raw, "*", base::CompareCase::SENSITIVE)) |
| 341 raw = "*" + raw; | 339 raw = "*" + raw; |
| 342 | 340 |
| 343 return AddRuleForHostname(scheme, raw, port); | 341 return AddRuleForHostname(scheme, raw, port); |
| 344 } | 342 } |
| 345 | 343 |
| 346 bool ProxyBypassRules::AddRuleFromStringInternalWithLogging( | 344 bool ProxyBypassRules::AddRuleFromStringInternalWithLogging( |
| 347 const std::string& raw, | 345 const std::string& raw, |
| 348 bool use_hostname_suffix_matching) { | 346 bool use_hostname_suffix_matching) { |
| 349 return AddRuleFromStringInternal(raw, use_hostname_suffix_matching); | 347 return AddRuleFromStringInternal(raw, use_hostname_suffix_matching); |
| 350 } | 348 } |
| 351 | 349 |
| 352 } // namespace net | 350 } // namespace net |
| OLD | NEW |