| 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/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
| 10 #include "base/strings/string_tokenizer.h" | 11 #include "base/strings/string_tokenizer.h" |
| 11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 13 #include "net/base/host_port_pair.h" | 14 #include "net/base/host_port_pair.h" |
| 14 #include "net/base/net_util.h" | 15 #include "net/base/net_util.h" |
| 15 | 16 |
| 16 namespace net { | 17 namespace net { |
| 17 | 18 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 29 | 30 |
| 30 bool Matches(const GURL& url) const override { | 31 bool Matches(const GURL& url) const override { |
| 31 if (optional_port_ != -1 && url.EffectiveIntPort() != optional_port_) | 32 if (optional_port_ != -1 && url.EffectiveIntPort() != optional_port_) |
| 32 return false; // Didn't match port expectation. | 33 return false; // Didn't match port expectation. |
| 33 | 34 |
| 34 if (!optional_scheme_.empty() && url.scheme() != optional_scheme_) | 35 if (!optional_scheme_.empty() && url.scheme() != optional_scheme_) |
| 35 return false; // Didn't match scheme expectation. | 36 return false; // Didn't match scheme expectation. |
| 36 | 37 |
| 37 // Note it is necessary to lower-case the host, since GURL uses capital | 38 // Note it is necessary to lower-case the host, since GURL uses capital |
| 38 // letters for percent-escaped characters. | 39 // letters for percent-escaped characters. |
| 39 return MatchPattern(base::StringToLowerASCII(url.host()), | 40 return base::MatchPattern(base::StringToLowerASCII(url.host()), |
| 40 hostname_pattern_); | 41 hostname_pattern_); |
| 41 } | 42 } |
| 42 | 43 |
| 43 std::string ToString() const override { | 44 std::string ToString() const override { |
| 44 std::string str; | 45 std::string str; |
| 45 if (!optional_scheme_.empty()) | 46 if (!optional_scheme_.empty()) |
| 46 base::StringAppendF(&str, "%s://", optional_scheme_.c_str()); | 47 base::StringAppendF(&str, "%s://", optional_scheme_.c_str()); |
| 47 str += hostname_pattern_; | 48 str += hostname_pattern_; |
| 48 if (optional_port_ != -1) | 49 if (optional_port_ != -1) |
| 49 base::StringAppendF(&str, ":%d", optional_port_); | 50 base::StringAppendF(&str, ":%d", optional_port_); |
| 50 return str; | 51 return str; |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 } | 257 } |
| 257 | 258 |
| 258 bool ProxyBypassRules::AddRuleFromStringInternal( | 259 bool ProxyBypassRules::AddRuleFromStringInternal( |
| 259 const std::string& raw_untrimmed, | 260 const std::string& raw_untrimmed, |
| 260 bool use_hostname_suffix_matching) { | 261 bool use_hostname_suffix_matching) { |
| 261 std::string raw; | 262 std::string raw; |
| 262 base::TrimWhitespaceASCII(raw_untrimmed, base::TRIM_ALL, &raw); | 263 base::TrimWhitespaceASCII(raw_untrimmed, base::TRIM_ALL, &raw); |
| 263 | 264 |
| 264 // This is the special syntax used by WinInet's bypass list -- we allow it | 265 // This is the special syntax used by WinInet's bypass list -- we allow it |
| 265 // on all platforms and interpret it the same way. | 266 // on all platforms and interpret it the same way. |
| 266 if (LowerCaseEqualsASCII(raw, "<local>")) { | 267 if (base::LowerCaseEqualsASCII(raw, "<local>")) { |
| 267 AddRuleToBypassLocal(); | 268 AddRuleToBypassLocal(); |
| 268 return true; | 269 return true; |
| 269 } | 270 } |
| 270 | 271 |
| 271 // Extract any scheme-restriction. | 272 // Extract any scheme-restriction. |
| 272 std::string::size_type scheme_pos = raw.find("://"); | 273 std::string::size_type scheme_pos = raw.find("://"); |
| 273 std::string scheme; | 274 std::string scheme; |
| 274 if (scheme_pos != std::string::npos) { | 275 if (scheme_pos != std::string::npos) { |
| 275 scheme = raw.substr(0, scheme_pos); | 276 scheme = raw.substr(0, scheme_pos); |
| 276 raw = raw.substr(scheme_pos + 3); | 277 raw = raw.substr(scheme_pos + 3); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 raw.end()), | 321 raw.end()), |
| 321 &port) || | 322 &port) || |
| 322 (port < 0 || port > 0xFFFF)) { | 323 (port < 0 || port > 0xFFFF)) { |
| 323 return false; // Port was invalid. | 324 return false; // Port was invalid. |
| 324 } | 325 } |
| 325 raw = raw.substr(0, pos_colon); | 326 raw = raw.substr(0, pos_colon); |
| 326 } | 327 } |
| 327 | 328 |
| 328 // Special-case hostnames that begin with a period. | 329 // Special-case hostnames that begin with a period. |
| 329 // For example, we remap ".google.com" --> "*.google.com". | 330 // For example, we remap ".google.com" --> "*.google.com". |
| 330 if (StartsWithASCII(raw, ".", false)) | 331 if (base::StartsWith(raw, ".", base::CompareCase::SENSITIVE)) |
| 331 raw = "*" + raw; | 332 raw = "*" + raw; |
| 332 | 333 |
| 333 // If suffix matching was asked for, make sure the pattern starts with a | 334 // If suffix matching was asked for, make sure the pattern starts with a |
| 334 // wildcard. | 335 // wildcard. |
| 335 if (use_hostname_suffix_matching && !StartsWithASCII(raw, "*", false)) | 336 if (use_hostname_suffix_matching && |
| 337 !base::StartsWith(raw, "*", base::CompareCase::SENSITIVE)) |
| 336 raw = "*" + raw; | 338 raw = "*" + raw; |
| 337 | 339 |
| 338 return AddRuleForHostname(scheme, raw, port); | 340 return AddRuleForHostname(scheme, raw, port); |
| 339 } | 341 } |
| 340 | 342 |
| 341 bool ProxyBypassRules::AddRuleFromStringInternalWithLogging( | 343 bool ProxyBypassRules::AddRuleFromStringInternalWithLogging( |
| 342 const std::string& raw, | 344 const std::string& raw, |
| 343 bool use_hostname_suffix_matching) { | 345 bool use_hostname_suffix_matching) { |
| 344 return AddRuleFromStringInternal(raw, use_hostname_suffix_matching); | 346 return AddRuleFromStringInternal(raw, use_hostname_suffix_matching); |
| 345 } | 347 } |
| 346 | 348 |
| 347 } // namespace net | 349 } // namespace net |
| OLD | NEW |