diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-19 20:24:06 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-19 20:24:06 +0000 |
commit | 7541206c7a5160f3489d563b97f1c841c853dc22 (patch) | |
tree | b69621265589060c0577559c23c86db4de667191 /net/proxy/proxy_service.cc | |
parent | d68a04da3be6a4a5db3768f53b2b48735a6ec210 (diff) | |
download | chromium_src-7541206c7a5160f3489d563b97f1c841c853dc22.zip chromium_src-7541206c7a5160f3489d563b97f1c841c853dc22.tar.gz chromium_src-7541206c7a5160f3489d563b97f1c841c853dc22.tar.bz2 |
Split out the handling of proxy bypass rules into ProxyBypassRules. There are some pretty complicated rules, and this helps isolate that code and better test it.
This also lays a framework for addressing bug 9835 (IP/CIDR matching)
Lastly, adds support for the exclusion format ".domain" on all platforms, which is interpreted as "*.domain".
BUG=28112
TEST=ProxyBypassRulesTest.*
Review URL: http://codereview.chromium.org/601070
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39486 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy/proxy_service.cc')
-rw-r--r-- | net/proxy/proxy_service.cc | 86 |
1 files changed, 1 insertions, 85 deletions
diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc index 90fd297..fa7ba4d 100644 --- a/net/proxy/proxy_service.cc +++ b/net/proxy/proxy_service.cc @@ -334,7 +334,7 @@ void ProxyService::ApplyProxyRules(const GURL& url, ProxyInfo* result) { DCHECK(!proxy_rules.empty()); - if (ShouldBypassProxyForURL(url)) { + if (config_.bypass_rules.Matches(url)) { result->UseDirect(); return; } @@ -692,90 +692,6 @@ void ProxyService::UpdateConfigIfOld(LoadLog* load_log) { UpdateConfig(load_log); } -bool ProxyService::ShouldBypassProxyForURL(const GURL& url) { - std::string url_domain = url.scheme(); - if (!url_domain.empty()) - url_domain += "://"; - - url_domain += url.host(); - // This isn't superfluous; GURL case canonicalization doesn't hit the embedded - // percent-encoded characters. - StringToLowerASCII(&url_domain); - - // TODO(eroman): use GetHostAndPort(). - std::string url_domain_and_port = url_domain + ":" - + IntToString(url.EffectiveIntPort()); - - if (config_.proxy_bypass_local_names && IsLocalName(url)) - return true; - - for(std::vector<std::string>::const_iterator i = config_.proxy_bypass.begin(); - i != config_.proxy_bypass.end(); ++i) { - std::string bypass_url_domain = *i; - - // The proxy server bypass list can contain entities with http/https - // If no scheme is specified then it indicates that all schemes are - // allowed for the current entry. For matching this we just use - // the protocol scheme of the url passed in. - size_t scheme_colon = bypass_url_domain.find("://"); - if (scheme_colon == std::string::npos) { - std::string bypass_url_domain_with_scheme = url.scheme(); - scheme_colon = bypass_url_domain_with_scheme.length(); - bypass_url_domain_with_scheme += "://"; - bypass_url_domain_with_scheme += bypass_url_domain; - - bypass_url_domain = bypass_url_domain_with_scheme; - } - std::string* url_compare_reference = &url_domain; - size_t port_colon = bypass_url_domain.rfind(":"); - if (port_colon > scheme_colon) { - // If our match pattern includes a colon followed by a digit, - // and either it's preceded by ']' (IPv6 with port) - // or has no other colon (IPv4), - // then match against <domain>:<port>. - // TODO(sdoyon): straighten this out, in particular the IPv6 brackets, - // and do the parsing in ProxyConfig when we do the CIDR matching - // mentioned below. - std::string::const_iterator domain_begin = - bypass_url_domain.begin() + scheme_colon + 3; // after :// - std::string::const_iterator port_iter = - bypass_url_domain.begin() + port_colon; - std::string::const_iterator end = bypass_url_domain.end(); - if ((port_iter + 1) < end && IsAsciiDigit(*(port_iter + 1)) && - (*(port_iter - 1) == ']' || - std::find(domain_begin, port_iter, ':') == port_iter)) - url_compare_reference = &url_domain_and_port; - } - - StringToLowerASCII(&bypass_url_domain); - - if (MatchPatternASCII(*url_compare_reference, bypass_url_domain)) - return true; - - // Some systems (the Mac, for example) allow CIDR-style specification of - // proxy bypass for IP-specified hosts (e.g. "10.0.0.0/8"; see - // http://www.tcd.ie/iss/internet/osx_proxy.php for a real-world example). - // That's kinda cool so we'll provide that for everyone. - // TODO(avi): implement here. See: http://crbug.com/9835. - // IP addresses ought to be canonicalized for comparison (whether - // with CIDR, port, or IP address alone). - } - - return false; -} - -// This matches IE's interpretation of the -// "Bypass proxy server for local addresses" settings checkbox. Fully -// qualified domain names or IP addresses are considered non-local, -// regardless of what they map to. -// -// static -bool ProxyService::IsLocalName(const GURL& url) { - const std::string& host = url.host(); - if (host == "127.0.0.1" || host == "[::1]") - return true; - return host.find('.') == std::string::npos; -} void ProxyService::OnIPAddressChanged() { DCHECK(network_change_notifier_); |