summaryrefslogtreecommitdiffstats
path: root/net/proxy/proxy_config.h
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-31 01:03:23 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-31 01:03:23 +0000
commit5b45aec04af2be235787c81369c77d627ebd639a (patch)
treeaf51655c9ca9374181722a96514f9b827cdceb34 /net/proxy/proxy_config.h
parent6dd6c74b945802513e94b4be1012ccfbe240f023 (diff)
downloadchromium_src-5b45aec04af2be235787c81369c77d627ebd639a.zip
chromium_src-5b45aec04af2be235787c81369c77d627ebd639a.tar.gz
chromium_src-5b45aec04af2be235787c81369c77d627ebd639a.tar.bz2
Extract the parsing of proxy rules to ProxyConfig::ProxyRules, and unit-test.
This avoids re-parsing the rules every time a proxy resolve is done, and also adds extra tolerance for white space. The other motivation is to not have to fiddle around with strings as much in the various ProxyConfigServceXXXX implementations. Review URL: http://codereview.chromium.org/57011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12829 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy/proxy_config.h')
-rw-r--r--net/proxy/proxy_config.h72
1 files changed, 56 insertions, 16 deletions
diff --git a/net/proxy/proxy_config.h b/net/proxy/proxy_config.h
index 5377ed7..5fca8fe 100644
--- a/net/proxy/proxy_config.h
+++ b/net/proxy/proxy_config.h
@@ -9,6 +9,7 @@
#include <vector>
#include "googleurl/src/gurl.h"
+#include "net/proxy/proxy_server.h"
namespace net {
@@ -32,22 +33,61 @@ class ProxyConfig {
// If non-empty, indicates the URL of the proxy auto-config file to use.
GURL pac_url;
- // If non-empty, indicates the proxy server to use, given by:
- //
- // proxy-uri = [<proxy-scheme>://]<proxy-host>[:"<proxy-port>]
- //
- // If the proxy to use depends on the scheme of the URL, can instead specify
- // a semicolon separated list of:
- //
- // <url-scheme>"="<proxy-uri>
- //
- // For example:
- // "http=foopy:80;ftp=foopy2" -- use HTTP proxy "foopy:80" for http URLs,
- // and HTTP proxy "foopy2:80" for ftp URLs.
- // "foopy:80" -- use HTTP proxy "foopy:80" for all URLs.
- // "socks4://foopy" -- use SOCKS v4 proxy "foopy:1080" for all
- // URLs.
- std::string proxy_rules;
+ struct ProxyRules {
+ enum Type {
+ TYPE_NO_RULES,
+ TYPE_SINGLE_PROXY,
+ TYPE_PROXY_PER_SCHEME,
+ };
+
+ ProxyRules() : type(TYPE_NO_RULES) {}
+
+ bool empty() const {
+ return type == TYPE_NO_RULES;
+ }
+
+ // Parses the rules from a string, indicating which proxies to use.
+ //
+ // proxy-uri = [<proxy-scheme>://]<proxy-host>[:"<proxy-port>]
+ //
+ // If the proxy to use depends on the scheme of the URL, can instead specify
+ // a semicolon separated list of:
+ //
+ // <url-scheme>"="<proxy-uri>
+ //
+ // For example:
+ // "http=foopy:80;ftp=foopy2" -- use HTTP proxy "foopy:80" for http URLs,
+ // and HTTP proxy "foopy2:80" for ftp URLs.
+ // "foopy:80" -- use HTTP proxy "foopy:80" for all URLs.
+ // "socks4://foopy" -- use SOCKS v4 proxy "foopy:1080" for all
+ // 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;
+
+ 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;
+ }
+
+ Type type;
+
+ // Set if |type| is TYPE_SINGLE_PROXY.
+ ProxyServer single_proxy;
+
+ // Set if |type| is TYPE_PROXY_PER_SCHEME.
+ ProxyServer proxy_for_http;
+ ProxyServer proxy_for_https;
+ ProxyServer proxy_for_ftp;
+ };
+
+ ProxyRules proxy_rules;
// Indicates a list of hosts that should bypass any proxy configuration. For
// these hosts, a direct connection should always be used.