diff options
author | arindam@chromium.org <arindam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-14 05:23:30 +0000 |
---|---|---|
committer | arindam@chromium.org <arindam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-14 05:23:30 +0000 |
commit | 87a102b1bd6d2e450f10ed0931c09ffcfef9a51c (patch) | |
tree | 6877259bfdf9ec82c9952a1f66d9d450c037f331 /net | |
parent | 565243e032009b7022b49c085b1157c3fb4986d4 (diff) | |
download | chromium_src-87a102b1bd6d2e450f10ed0931c09ffcfef9a51c.zip chromium_src-87a102b1bd6d2e450f10ed0931c09ffcfef9a51c.tar.gz chromium_src-87a102b1bd6d2e450f10ed0931c09ffcfef9a51c.tar.bz2 |
Whenever proxy configurations contain socks and http/https/ftp proxies, socks configuration over rid the other proxies. Fixes the issue. Attached test cases.
BUG=15738
TEST=unittest (ProxyConfigTest.ParseProxyRules, ProxyServiceTest.DefaultProxyFallbackToSOCKS)
Review URL: http://codereview.chromium.org/149191
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20605 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/proxy/proxy_config.cc | 42 | ||||
-rw-r--r-- | net/proxy/proxy_config.h | 21 | ||||
-rw-r--r-- | net/proxy/proxy_config_service_common_unittest.cc | 29 | ||||
-rw-r--r-- | net/proxy/proxy_config_service_common_unittest.h | 9 | ||||
-rw-r--r-- | net/proxy/proxy_config_service_linux.cc | 7 | ||||
-rw-r--r-- | net/proxy/proxy_config_service_win_unittest.cc | 19 | ||||
-rw-r--r-- | net/proxy/proxy_config_unittest.cc | 53 | ||||
-rw-r--r-- | net/proxy/proxy_list.cc | 2 | ||||
-rw-r--r-- | net/proxy/proxy_server.cc | 12 | ||||
-rw-r--r-- | net/proxy/proxy_server.h | 11 | ||||
-rw-r--r-- | net/proxy/proxy_server_unittest.cc | 13 | ||||
-rw-r--r-- | net/proxy/proxy_service.cc | 2 | ||||
-rw-r--r-- | net/proxy/proxy_service_unittest.cc | 46 |
13 files changed, 211 insertions, 55 deletions
diff --git a/net/proxy/proxy_config.cc b/net/proxy/proxy_config.cc index 8ae4baa..ab719e6 100644 --- a/net/proxy/proxy_config.cc +++ b/net/proxy/proxy_config.cc @@ -36,6 +36,7 @@ void ProxyConfig::ProxyRules::ParseFromString(const std::string& proxy_rules) { proxy_for_http = ProxyServer(); proxy_for_https = ProxyServer(); proxy_for_ftp = ProxyServer(); + socks_proxy = ProxyServer(); StringTokenizer proxy_server_list(proxy_rules, ";"); while (proxy_server_list.GetNext()) { @@ -51,18 +52,8 @@ void ProxyConfig::ProxyRules::ParseFromString(const std::string& proxy_rules) { if (!proxy_server_for_scheme.GetNext()) { if (type == TYPE_PROXY_PER_SCHEME) continue; // Unexpected. - single_proxy = ProxyServer::FromURI(url_scheme); - type = TYPE_SINGLE_PROXY; - return; - } - - // If the proxy settings has only socks and others blank, - // make that the default for all the proxies - // This gets hit only on windows when using IE settings. - if (url_scheme == "socks") { - std::string proxy_server_string = "socks://"; - proxy_server_string.append(proxy_server_for_scheme.token()); - single_proxy = ProxyServer::FromURI(proxy_server_string); + single_proxy = ProxyServer::FromURI(url_scheme, + ProxyServer::SCHEME_HTTP); type = TYPE_SINGLE_PROXY; return; } @@ -72,15 +63,29 @@ void ProxyConfig::ProxyRules::ParseFromString(const std::string& proxy_rules) { // Add it to the per-scheme mappings (if supported scheme). type = TYPE_PROXY_PER_SCHEME; - if (const ProxyServer* entry = MapSchemeToProxy(url_scheme)) - *const_cast<ProxyServer*>(entry) = - ProxyServer::FromURI(proxy_server_for_scheme.token()); + if (ProxyServer* entry = MapSchemeToProxy(url_scheme)) { + std::string proxy_server_token = proxy_server_for_scheme.token(); + ProxyServer::Scheme scheme = (entry == &socks_proxy) ? + ProxyServer::SCHEME_SOCKS4 : ProxyServer::SCHEME_HTTP; + *entry = ProxyServer::FromURI(proxy_server_token, scheme); + } } } } -const ProxyServer* ProxyConfig::ProxyRules::MapSchemeToProxy( - const std::string& scheme) const { +const ProxyServer* ProxyConfig::ProxyRules::MapUrlSchemeToProxy( + const std::string& url_scheme) const { + const ProxyServer* proxy_server = + const_cast<ProxyRules*>(this)->MapSchemeToProxy(url_scheme); + if (proxy_server && proxy_server->is_valid()) + return proxy_server; + if (socks_proxy.is_valid()) + return &socks_proxy; + return NULL; // No mapping for this scheme. Use direct. +} + +ProxyServer* ProxyConfig::ProxyRules::MapSchemeToProxy( + const std::string& scheme) { DCHECK(type == TYPE_PROXY_PER_SCHEME); if (scheme == "http") return &proxy_for_http; @@ -88,6 +93,8 @@ const ProxyServer* ProxyConfig::ProxyRules::MapSchemeToProxy( return &proxy_for_https; if (scheme == "ftp") return &proxy_for_ftp; + if (scheme == "socks") + return &socks_proxy; return NULL; // No mapping for this scheme. } @@ -194,6 +201,7 @@ std::ostream& operator<<(std::ostream& out, << " proxy_for_http: " << rules.proxy_for_http << "\n" << " proxy_for_https: " << rules.proxy_for_https << "\n" << " proxy_for_ftp: " << rules.proxy_for_ftp << "\n" + << " socks_proxy: " << rules.socks_proxy << "\n" << " }"; } diff --git a/net/proxy/proxy_config.h b/net/proxy/proxy_config.h index f9bc6d4..c48f74b 100644 --- a/net/proxy/proxy_config.h +++ b/net/proxy/proxy_config.h @@ -68,17 +68,20 @@ class ProxyConfig { // URLs. void ParseFromString(const std::string& proxy_rules); - // Returns one of {&proxy_for_http, &proxy_for_https, &proxy_for_ftp}, - // or NULL if it is a scheme that we don't have a mapping for. Should only - // call this if the type is TYPE_PROXY_PER_SCHEME. - const ProxyServer* MapSchemeToProxy(const std::string& scheme) const; + // Returns one of {&proxy_for_http, &proxy_for_https, &proxy_for_ftp, + // &socks_proxy}, or NULL if it is a scheme that we don't have a mapping + // for. If the scheme mapping is not present and socks_proxy is defined, + // we fall back to using socks_proxy. + // Should only call this if the type is TYPE_PROXY_PER_SCHEME. + const ProxyServer* MapUrlSchemeToProxy(const std::string& url_scheme) const; bool operator==(const ProxyRules& other) const { return type == other.type && single_proxy == other.single_proxy && proxy_for_http == other.proxy_for_http && proxy_for_https == other.proxy_for_https && - proxy_for_ftp == other.proxy_for_ftp; + proxy_for_ftp == other.proxy_for_ftp && + socks_proxy == other.socks_proxy; } Type type; @@ -90,6 +93,14 @@ class ProxyConfig { ProxyServer proxy_for_http; ProxyServer proxy_for_https; ProxyServer proxy_for_ftp; + + // Set if configuration has SOCKS proxy. + ProxyServer socks_proxy; + private: + // Returns one of {&proxy_for_http, &proxy_for_https, &proxy_for_ftp, + // &socks_proxy}, or NULL if it is a scheme that we don't have a mapping + // for. Should only call this if the type is TYPE_PROXY_PER_SCHEME. + ProxyServer* MapSchemeToProxy(const std::string& scheme); }; ProxyRules proxy_rules; diff --git a/net/proxy/proxy_config_service_common_unittest.cc b/net/proxy/proxy_config_service_common_unittest.cc index 06f1c6a..1a61468 100644 --- a/net/proxy/proxy_config_service_common_unittest.cc +++ b/net/proxy/proxy_config_service_common_unittest.cc @@ -16,19 +16,26 @@ ProxyConfig::ProxyRules MakeProxyRules( const char* single_proxy, const char* proxy_for_http, const char* proxy_for_https, - const char* proxy_for_ftp) { + const char* proxy_for_ftp, + const char* socks_proxy) { ProxyConfig::ProxyRules rules; rules.type = type; - rules.single_proxy = ProxyServer::FromURI(single_proxy); - rules.proxy_for_http = ProxyServer::FromURI(proxy_for_http); - rules.proxy_for_https = ProxyServer::FromURI(proxy_for_https); - rules.proxy_for_ftp = ProxyServer::FromURI(proxy_for_ftp); + rules.single_proxy = ProxyServer::FromURI(single_proxy, + ProxyServer::SCHEME_HTTP); + rules.proxy_for_http = ProxyServer::FromURI(proxy_for_http, + ProxyServer::SCHEME_HTTP); + rules.proxy_for_https = ProxyServer::FromURI(proxy_for_https, + ProxyServer::SCHEME_HTTP); + rules.proxy_for_ftp = ProxyServer::FromURI(proxy_for_ftp, + ProxyServer::SCHEME_HTTP); + rules.socks_proxy = ProxyServer::FromURI(socks_proxy, + ProxyServer::SCHEME_SOCKS4); return rules; } ProxyConfig::ProxyRules MakeSingleProxyRules(const char* single_proxy) { return MakeProxyRules(ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, - single_proxy, "", "", ""); + single_proxy, "", "", "", ""); } ProxyConfig::ProxyRules MakeProxyPerSchemeRules( @@ -36,7 +43,15 @@ ProxyConfig::ProxyRules MakeProxyPerSchemeRules( const char* proxy_https, const char* proxy_ftp) { return MakeProxyRules(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, - "", proxy_http, proxy_https, proxy_ftp); + "", proxy_http, proxy_https, proxy_ftp, ""); +} +ProxyConfig::ProxyRules MakeProxyPerSchemeRules( + const char* proxy_http, + const char* proxy_https, + const char* proxy_ftp, + const char* socks_proxy) { + return MakeProxyRules(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, + "", proxy_http, proxy_https, proxy_ftp, socks_proxy); } std::string FlattenProxyBypass(const BypassList& proxy_bypass) { diff --git a/net/proxy/proxy_config_service_common_unittest.h b/net/proxy/proxy_config_service_common_unittest.h index 08487ec..783fc6f 100644 --- a/net/proxy/proxy_config_service_common_unittest.h +++ b/net/proxy/proxy_config_service_common_unittest.h @@ -19,7 +19,8 @@ ProxyConfig::ProxyRules MakeProxyRules( const char* single_proxy, const char* proxy_for_http, const char* proxy_for_https, - const char* proxy_for_ftp); + const char* proxy_for_ftp, + const char* socks_proxy); ProxyConfig::ProxyRules MakeSingleProxyRules(const char* single_proxy); @@ -28,6 +29,12 @@ ProxyConfig::ProxyRules MakeProxyPerSchemeRules( const char* proxy_https, const char* proxy_ftp); +ProxyConfig::ProxyRules MakeProxyPerSchemeRules( + const char* proxy_http, + const char* proxy_https, + const char* proxy_ftp, + const char* socks_proxy); + typedef std::vector<std::string> BypassList; // Joins the proxy bypass list using "\n" to make it into a single string. diff --git a/net/proxy/proxy_config_service_linux.cc b/net/proxy/proxy_config_service_linux.cc index 7c53258..a9efab2 100644 --- a/net/proxy/proxy_config_service_linux.cc +++ b/net/proxy/proxy_config_service_linux.cc @@ -55,6 +55,7 @@ class EnvironmentVariableGetterImpl // an appropriate proxy server scheme prefix. // scheme indicates the desired proxy scheme: usually http, with // socks 4 or 5 as special cases. +// TODO(arindam): Remove URI string manipulation by using MapUrlSchemeToProxy. std::string FixupProxyHostScheme(ProxyServer::Scheme scheme, std::string host) { if (scheme == ProxyServer::SCHEME_SOCKS4 && @@ -94,7 +95,8 @@ bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVarForScheme( if (env_var_getter_->Getenv(variable, &env_value)) { if (!env_value.empty()) { env_value = FixupProxyHostScheme(scheme, env_value); - ProxyServer proxy_server = ProxyServer::FromURI(env_value); + ProxyServer proxy_server = + ProxyServer::FromURI(env_value, ProxyServer::SCHEME_HTTP); if (proxy_server.is_valid() && !proxy_server.is_direct()) { *result_server = proxy_server; return true; @@ -402,7 +404,8 @@ bool ProxyConfigServiceLinux::Delegate::GetProxyFromGConf( host = FixupProxyHostScheme( is_socks ? ProxyServer::SCHEME_SOCKS4 : ProxyServer::SCHEME_HTTP, host); - ProxyServer proxy_server = ProxyServer::FromURI(host); + ProxyServer proxy_server = ProxyServer::FromURI(host, + ProxyServer::SCHEME_HTTP); if (proxy_server.is_valid()) { *result_server = proxy_server; return true; diff --git a/net/proxy/proxy_config_service_win_unittest.cc b/net/proxy/proxy_config_service_win_unittest.cc index c08b1a9..2b0ff66 100644 --- a/net/proxy/proxy_config_service_win_unittest.cc +++ b/net/proxy/proxy_config_service_win_unittest.cc @@ -108,6 +108,25 @@ TEST(ProxyConfigServiceWinTest, SetFromIEConfig) { false, // bypass_local_names }, + // SOCKS proxy configuration + { + { // Input. + FALSE, // fAutoDetect + NULL, // lpszAutoConfigUrl + L"http=www.google.com:80;https=www.foo.com:110;" + L"ftp=ftpproxy:20;socks=foopy:130", // lpszProxy + NULL, // lpszProxy_bypass + }, + + // Expected result. + false, // auto_detect + GURL(), // pac_url + MakeProxyPerSchemeRules("www.google.com:80", "www.foo.com:110", + "ftpproxy:20", "foopy:130"), + "", // proxy_bypass_list + false, // bypass_local_names + }, + // Bypass local names. { { // Input. diff --git a/net/proxy/proxy_config_unittest.cc b/net/proxy/proxy_config_unittest.cc index 06456834..d7ae65b 100644 --- a/net/proxy/proxy_config_unittest.cc +++ b/net/proxy/proxy_config_unittest.cc @@ -49,18 +49,21 @@ TEST(ProxyConfigTest, Equals) { // Test |ProxyConfig::proxy_rules|. config2.proxy_rules.type = net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; - config2.proxy_rules.single_proxy = net::ProxyServer::FromURI("myproxy:80"); + config2.proxy_rules.single_proxy = + net::ProxyServer::FromURI("myproxy:80", net::ProxyServer::SCHEME_HTTP); EXPECT_FALSE(config1.Equals(config2)); EXPECT_FALSE(config2.Equals(config1)); config1.proxy_rules.type = net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; - config1.proxy_rules.single_proxy = net::ProxyServer::FromURI("myproxy:100"); + config1.proxy_rules.single_proxy = + net::ProxyServer::FromURI("myproxy:100", net::ProxyServer::SCHEME_HTTP); EXPECT_FALSE(config1.Equals(config2)); EXPECT_FALSE(config2.Equals(config1)); - config1.proxy_rules.single_proxy = net::ProxyServer::FromURI("myproxy"); + config1.proxy_rules.single_proxy = + net::ProxyServer::FromURI("myproxy", net::ProxyServer::SCHEME_HTTP); EXPECT_TRUE(config1.Equals(config2)); EXPECT_TRUE(config2.Equals(config1)); @@ -99,6 +102,7 @@ TEST(ProxyConfigTest, ParseProxyRules) { const char* proxy_for_http; const char* proxy_for_https; const char* proxy_for_ftp; + const char* socks_proxy; } tests[] = { // One HTTP proxy for all schemes. { @@ -109,6 +113,7 @@ TEST(ProxyConfigTest, ParseProxyRules) { NULL, NULL, NULL, + NULL, }, // Only specify a proxy server for "http://" urls. @@ -120,6 +125,7 @@ TEST(ProxyConfigTest, ParseProxyRules) { "myproxy:80", NULL, NULL, + NULL, }, // Specify an HTTP proxy for "ftp://" and a SOCKS proxy for "https://" urls. @@ -131,6 +137,7 @@ TEST(ProxyConfigTest, ParseProxyRules) { NULL, "socks4://foopy:1080", "ftp-proxy:80", + NULL, }, // Give a scheme-specific proxy as well as a non-scheme specific. @@ -144,6 +151,7 @@ TEST(ProxyConfigTest, ParseProxyRules) { NULL, NULL, NULL, + NULL, }, // Give a scheme-specific proxy as well as a non-scheme specific. @@ -157,6 +165,7 @@ TEST(ProxyConfigTest, ParseProxyRules) { NULL, NULL, "ftp-proxy:80", + NULL, }, // Include duplicate entries -- last one wins. @@ -168,19 +177,46 @@ TEST(ProxyConfigTest, ParseProxyRules) { NULL, NULL, "ftp3:80", + NULL, }, - // Only socks proxy present, others being blank. - { // NOLINT + // Only SOCKS proxy present, others being blank. + { "socks=foopy", - net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, - "socks4://foopy:1080", + net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, NULL, NULL, NULL, + NULL, + "socks4://foopy:1080", + }, + + // SOCKS proxy present along with other proxies too + { + "http=httpproxy ; https=httpsproxy ; ftp=ftpproxy ; socks=foopy ", + + net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, + NULL, + "httpproxy:80", + "httpsproxy:80", + "ftpproxy:80", + "socks4://foopy:1080", }, + // SOCKS proxy (with modifier) present along with some proxies + // (FTP being blank) + { + "http=httpproxy ; https=httpsproxy ; socks=socks5://foopy ", + + net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, + NULL, + "httpproxy:80", + "httpsproxy:80", + NULL, + "socks5://foopy:1080", + }, + // Include unsupported schemes -- they are discarded. { "crazy=foopy ; foo=bar ; https=myhttpsproxy", @@ -190,6 +226,7 @@ TEST(ProxyConfigTest, ParseProxyRules) { NULL, "myhttpsproxy:80", NULL, + NULL, }, }; @@ -207,6 +244,8 @@ TEST(ProxyConfigTest, ParseProxyRules) { config.proxy_rules.proxy_for_https); ExpectProxyServerEquals(tests[i].proxy_for_ftp, config.proxy_rules.proxy_for_ftp); + ExpectProxyServerEquals(tests[i].socks_proxy, + config.proxy_rules.socks_proxy); } } diff --git a/net/proxy/proxy_list.cc b/net/proxy/proxy_list.cc index e390bbc..e12edf4 100644 --- a/net/proxy/proxy_list.cc +++ b/net/proxy/proxy_list.cc @@ -18,7 +18,7 @@ void ProxyList::Set(const std::string& proxy_uri_list) { StringTokenizer str_tok(proxy_uri_list, ";"); while (str_tok.GetNext()) { ProxyServer uri = ProxyServer::FromURI( - str_tok.token_begin(), str_tok.token_end()); + str_tok.token_begin(), str_tok.token_end(), ProxyServer::SCHEME_HTTP); // Silently discard malformed inputs. if (uri.is_valid()) proxies_.push_back(uri); diff --git a/net/proxy/proxy_server.cc b/net/proxy/proxy_server.cc index 50bf4d9..6c47fee 100644 --- a/net/proxy/proxy_server.cc +++ b/net/proxy/proxy_server.cc @@ -85,15 +85,17 @@ std::string ProxyServer::host_and_port() const { } // static -ProxyServer ProxyServer::FromURI(const std::string& uri) { - return FromURI(uri.begin(), uri.end()); +ProxyServer ProxyServer::FromURI(const std::string& uri, + Scheme default_scheme) { + return FromURI(uri.begin(), uri.end(), default_scheme); } // static ProxyServer ProxyServer::FromURI(std::string::const_iterator begin, - std::string::const_iterator end) { - // We will default to HTTP if no scheme specifier was given. - Scheme scheme = SCHEME_HTTP; + std::string::const_iterator end, + Scheme default_scheme) { + // We will default to |default_scheme| if no scheme specifier was given. + Scheme scheme = default_scheme; // Trim the leading/trailing whitespace. HttpUtil::TrimLWS(&begin, &end); diff --git a/net/proxy/proxy_server.h b/net/proxy/proxy_server.h index 9060c39..eb2d275 100644 --- a/net/proxy/proxy_server.h +++ b/net/proxy/proxy_server.h @@ -64,22 +64,23 @@ class ProxyServer { // Parse from an input with format: // [<scheme>"://"]<server>[":"<port>] // - // Both <scheme> and <port> are optional. If <scheme> is omitted, it will - // be assumed as "http". If <port> is omitted, it will be assumed as + // Both <scheme> and <port> are optional. If <scheme> is omitted, it will be + // assumed as |default_scheme|. If <port> is omitted, it will be assumed as // the default port for the chosen scheme (80 for "http", 1080 for "socks"). // // If parsing fails the instance will be set to invalid. // - // Examples: + // Examples (for |default_scheme| = SCHEME_HTTP ): // "foopy" {scheme=HTTP, host="foopy", port=80} // "socks4://foopy" {scheme=SOCKS4, host="foopy", port=1080} // "socks5://foopy" {scheme=SOCKS5, host="foopy", port=1080} // "http://foopy:17" {scheme=HTTP, host="foopy", port=17} // "direct://" {scheme=DIRECT} // "foopy:X" INVALID -- bad port. - static ProxyServer FromURI(const std::string& uri); + static ProxyServer FromURI(const std::string& uri, Scheme default_scheme); static ProxyServer FromURI(std::string::const_iterator uri_begin, - std::string::const_iterator uri_end); + std::string::const_iterator uri_end, + Scheme default_scheme); // Format as a URI string. This does the reverse of FromURI. std::string ToURI() const; diff --git a/net/proxy/proxy_server_unittest.cc b/net/proxy/proxy_server_unittest.cc index 3257851..0b06152 100644 --- a/net/proxy/proxy_server_unittest.cc +++ b/net/proxy/proxy_server_unittest.cc @@ -148,7 +148,9 @@ TEST(ProxyServerTest, FromURI) { }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { - net::ProxyServer uri = net::ProxyServer::FromURI(tests[i].input_uri); + net::ProxyServer uri = + net::ProxyServer::FromURI(tests[i].input_uri, + net::ProxyServer::SCHEME_HTTP); EXPECT_TRUE(uri.is_valid()); EXPECT_FALSE(uri.is_direct()); EXPECT_EQ(tests[i].expected_uri, uri.ToURI()); @@ -168,7 +170,8 @@ TEST(ProxyServerTest, DefaultConstructor) { // Test parsing of the special URI form "direct://". Analagous to the "DIRECT" // entry in a PAC result. TEST(ProxyServerTest, Direct) { - net::ProxyServer uri = net::ProxyServer::FromURI("direct://"); + net::ProxyServer uri = + net::ProxyServer::FromURI("direct://", net::ProxyServer::SCHEME_HTTP); EXPECT_TRUE(uri.is_valid()); EXPECT_TRUE(uri.is_direct()); EXPECT_EQ("direct://", uri.ToURI()); @@ -190,7 +193,8 @@ TEST(ProxyServerTest, Invalid) { }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { - net::ProxyServer uri = net::ProxyServer::FromURI(tests[i]); + net::ProxyServer uri = + net::ProxyServer::FromURI(tests[i], net::ProxyServer::SCHEME_HTTP); EXPECT_FALSE(uri.is_valid()); EXPECT_FALSE(uri.is_direct()); EXPECT_FALSE(uri.is_http()); @@ -207,7 +211,8 @@ TEST(ProxyServerTest, Whitespace) { }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { - net::ProxyServer uri = net::ProxyServer::FromURI(tests[i]); + net::ProxyServer uri = + net::ProxyServer::FromURI(tests[i], net::ProxyServer::SCHEME_HTTP); EXPECT_EQ("foopy:80", uri.ToURI()); } } diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc index 3a0cd7f..e59c296 100644 --- a/net/proxy/proxy_service.cc +++ b/net/proxy/proxy_service.cc @@ -333,7 +333,7 @@ void ProxyService::ApplyProxyRules(const GURL& url, result->UseProxyServer(proxy_rules.single_proxy); break; case ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME: { - const ProxyServer* entry = proxy_rules.MapSchemeToProxy(url.scheme()); + const ProxyServer* entry = proxy_rules.MapUrlSchemeToProxy(url.scheme()); if (entry) { result->UseProxyServer(*entry); } else { diff --git a/net/proxy/proxy_service_unittest.cc b/net/proxy/proxy_service_unittest.cc index a33dfce..6774f2e 100644 --- a/net/proxy/proxy_service_unittest.cc +++ b/net/proxy/proxy_service_unittest.cc @@ -943,6 +943,52 @@ TEST(ProxyServiceTest, PerProtocolProxyTests) { EXPECT_EQ("foopy1:8080", info4.proxy_server().ToURI()); } +// If only HTTP and a SOCKS proxy are specified, check if ftp/https queries +// fall back to the SOCKS proxy. +TEST(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { + net::ProxyConfig config; + config.proxy_rules.ParseFromString("http=foopy1:8080;socks=foopy2:1080"); + config.auto_detect = false; + EXPECT_EQ(net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, + config.proxy_rules.type); + + SyncProxyService service1(new MockProxyConfigService(config), + new MockProxyResolver); + GURL test_url1("http://www.msn.com"); + net::ProxyInfo info1; + int rv = service1.ResolveProxy(test_url1, &info1); + EXPECT_EQ(net::OK, rv); + EXPECT_FALSE(info1.is_direct()); + EXPECT_EQ("foopy1:8080", info1.proxy_server().ToURI()); + + SyncProxyService service2(new MockProxyConfigService(config), + new MockProxyResolver); + GURL test_url2("ftp://ftp.google.com"); + net::ProxyInfo info2; + rv = service2.ResolveProxy(test_url2, &info2); + EXPECT_EQ(net::OK, rv); + EXPECT_FALSE(info2.is_direct()); + EXPECT_EQ("socks4://foopy2:1080", info2.proxy_server().ToURI()); + + SyncProxyService service3(new MockProxyConfigService(config), + new MockProxyResolver); + GURL test_url3("https://webbranch.techcu.com"); + net::ProxyInfo info3; + rv = service3.ResolveProxy(test_url3, &info3); + EXPECT_EQ(net::OK, rv); + EXPECT_FALSE(info3.is_direct()); + EXPECT_EQ("socks4://foopy2:1080", info3.proxy_server().ToURI()); + + SyncProxyService service4(new MockProxyConfigService(config), + new MockProxyResolver); + GURL test_url4("www.microsoft.com"); + net::ProxyInfo info4; + rv = service4.ResolveProxy(test_url4, &info4); + EXPECT_EQ(net::OK, rv); + EXPECT_FALSE(info4.is_direct()); + EXPECT_EQ("socks4://foopy2:1080", info4.proxy_server().ToURI()); +} + // Test cancellation of a queued request. TEST(ProxyServiceTest, CancelQueuedRequest) { MockProxyConfigService* config_service = |