| 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/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
| 12 #include "base/strings/string_tokenizer.h" | 12 #include "base/strings/string_tokenizer.h" |
| 13 #include "net/base/net_util.h" | 13 #include "net/base/net_util.h" |
| 14 | 14 |
| 15 namespace net { | 15 namespace net { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 class HostnamePatternRule : public ProxyBypassRules::Rule { | 19 class HostnamePatternRule : public ProxyBypassRules::Rule { |
| 20 public: | 20 public: |
| 21 HostnamePatternRule(const std::string& optional_scheme, | 21 HostnamePatternRule(const std::string& optional_scheme, |
| 22 const std::string& hostname_pattern, | 22 const std::string& hostname_pattern, |
| 23 int optional_port) | 23 int optional_port) |
| 24 : optional_scheme_(StringToLowerASCII(optional_scheme)), | 24 : optional_scheme_(base::StringToLowerASCII(optional_scheme)), |
| 25 hostname_pattern_(StringToLowerASCII(hostname_pattern)), | 25 hostname_pattern_(base::StringToLowerASCII(hostname_pattern)), |
| 26 optional_port_(optional_port) { | 26 optional_port_(optional_port) { |
| 27 } | 27 } |
| 28 | 28 |
| 29 virtual bool Matches(const GURL& url) const OVERRIDE { | 29 virtual bool Matches(const GURL& url) const OVERRIDE { |
| 30 if (optional_port_ != -1 && url.EffectiveIntPort() != optional_port_) | 30 if (optional_port_ != -1 && url.EffectiveIntPort() != optional_port_) |
| 31 return false; // Didn't match port expectation. | 31 return false; // Didn't match port expectation. |
| 32 | 32 |
| 33 if (!optional_scheme_.empty() && url.scheme() != optional_scheme_) | 33 if (!optional_scheme_.empty() && url.scheme() != optional_scheme_) |
| 34 return false; // Didn't match scheme expectation. | 34 return false; // Didn't match scheme expectation. |
| 35 | 35 |
| 36 // Note it is necessary to lower-case the host, since GURL uses capital | 36 // Note it is necessary to lower-case the host, since GURL uses capital |
| 37 // letters for percent-escaped characters. | 37 // letters for percent-escaped characters. |
| 38 return MatchPattern(StringToLowerASCII(url.host()), hostname_pattern_); | 38 return MatchPattern(base::StringToLowerASCII(url.host()), |
| 39 hostname_pattern_); |
| 39 } | 40 } |
| 40 | 41 |
| 41 virtual std::string ToString() const OVERRIDE { | 42 virtual std::string ToString() const OVERRIDE { |
| 42 std::string str; | 43 std::string str; |
| 43 if (!optional_scheme_.empty()) | 44 if (!optional_scheme_.empty()) |
| 44 base::StringAppendF(&str, "%s://", optional_scheme_.c_str()); | 45 base::StringAppendF(&str, "%s://", optional_scheme_.c_str()); |
| 45 str += hostname_pattern_; | 46 str += hostname_pattern_; |
| 46 if (optional_port_ != -1) | 47 if (optional_port_ != -1) |
| 47 base::StringAppendF(&str, ":%d", optional_port_); | 48 base::StringAppendF(&str, ":%d", optional_port_); |
| 48 return str; | 49 return str; |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 return AddRuleForHostname(scheme, raw, port); | 339 return AddRuleForHostname(scheme, raw, port); |
| 339 } | 340 } |
| 340 | 341 |
| 341 bool ProxyBypassRules::AddRuleFromStringInternalWithLogging( | 342 bool ProxyBypassRules::AddRuleFromStringInternalWithLogging( |
| 342 const std::string& raw, | 343 const std::string& raw, |
| 343 bool use_hostname_suffix_matching) { | 344 bool use_hostname_suffix_matching) { |
| 344 return AddRuleFromStringInternal(raw, use_hostname_suffix_matching); | 345 return AddRuleFromStringInternal(raw, use_hostname_suffix_matching); |
| 345 } | 346 } |
| 346 | 347 |
| 347 } // namespace net | 348 } // namespace net |
| OLD | NEW |