Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef NET_PROXY_PROXY_CONFIG_H_ | 5 #ifndef NET_PROXY_PROXY_CONFIG_H_ |
| 6 #define NET_PROXY_PROXY_CONFIG_H_ | 6 #define NET_PROXY_PROXY_CONFIG_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 11 #include "net/base/net_export.h" | 11 #include "net/base/net_export.h" |
| 12 #include "net/proxy/proxy_bypass_rules.h" | 12 #include "net/proxy/proxy_bypass_rules.h" |
| 13 #include "net/proxy/proxy_config_source.h" | 13 #include "net/proxy/proxy_config_source.h" |
| 14 #include "net/proxy/proxy_list.h" | |
| 14 #include "net/proxy/proxy_server.h" | 15 #include "net/proxy/proxy_server.h" |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 class Value; | 18 class Value; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace net { | 21 namespace net { |
| 21 | 22 |
| 22 class ProxyInfo; | 23 class ProxyInfo; |
| 23 | 24 |
| 24 // ProxyConfig describes a user's proxy settings. | 25 // ProxyConfig describes a user's proxy settings. |
| 25 // | 26 // |
| 26 // There are two categories of proxy settings: | 27 // There are two categories of proxy settings: |
| 27 // (1) Automatic (indicates the methods to obtain a PAC script) | 28 // (1) Automatic (indicates the methods to obtain a PAC script) |
| 28 // (2) Manual (simple set of proxy servers per scheme, and bypass patterns) | 29 // (2) Manual (simple set of proxy servers per scheme, and bypass patterns) |
| 29 // | 30 // |
| 30 // When both automatic and manual settings are specified, the Automatic ones | 31 // When both automatic and manual settings are specified, the Automatic ones |
| 31 // take precedence over the manual ones. | 32 // take precedence over the manual ones. |
| 32 // | 33 // |
| 33 // For more details see: | 34 // For more details see: |
| 34 // http://www.chromium.org/developers/design-documents/proxy-settings-fallback | 35 // http://www.chromium.org/developers/design-documents/proxy-settings-fallback |
| 35 class NET_EXPORT ProxyConfig { | 36 class NET_EXPORT ProxyConfig { |
| 36 public: | 37 public: |
| 37 // ProxyRules describes the "manual" proxy settings. | 38 // ProxyRules describes the "manual" proxy settings. |
| 38 // TODO(eroman): Turn this into a class. | 39 // TODO(eroman): Turn this into a class. |
| 40 // TODO(marq): Update the enum names; "TYPE_SINGLE_PROXY" really means | |
| 41 // the same set of proxies are used for all requests. | |
| 39 struct NET_EXPORT ProxyRules { | 42 struct NET_EXPORT ProxyRules { |
| 40 enum Type { | 43 enum Type { |
| 41 TYPE_NO_RULES, | 44 TYPE_NO_RULES, |
| 42 TYPE_SINGLE_PROXY, | 45 TYPE_SINGLE_PROXY, |
| 43 TYPE_PROXY_PER_SCHEME, | 46 TYPE_PROXY_PER_SCHEME, |
| 44 }; | 47 }; |
| 45 | 48 |
| 46 // Note that the default of TYPE_NO_RULES results in direct connections | 49 // Note that the default of TYPE_NO_RULES results in direct connections |
| 47 // being made when using this ProxyConfig. | 50 // being made when using this ProxyConfig. |
| 48 ProxyRules(); | 51 ProxyRules(); |
| 49 ~ProxyRules(); | 52 ~ProxyRules(); |
| 50 | 53 |
| 51 bool empty() const { | 54 bool empty() const { |
| 52 return type == TYPE_NO_RULES; | 55 return type == TYPE_NO_RULES; |
| 53 } | 56 } |
| 54 | 57 |
| 55 // Sets |result| with the proxy to use for |url| based on the current rules. | 58 // Sets |result| with the proxies to use for |url| based on the current |
| 59 // rules. | |
| 56 void Apply(const GURL& url, ProxyInfo* result) const; | 60 void Apply(const GURL& url, ProxyInfo* result) const; |
| 57 | 61 |
| 58 // Parses the rules from a string, indicating which proxies to use. | 62 // Parses the rules from a string, indicating which proxies to use. |
| 59 // | 63 // |
| 60 // proxy-uri = [<proxy-scheme>"://"]<proxy-host>[":"<proxy-port>] | 64 // proxy-uri = [<proxy-scheme>"://"]<proxy-host>[":"<proxy-port>] |
| 61 // | 65 // |
| 62 // If the proxy to use depends on the scheme of the URL, can instead specify | 66 // proxy-uri-list = <proxy-uri>[","<proxy-uri-list>] |
| 63 // a semicolon separated list of: | |
| 64 // | 67 // |
| 65 // <url-scheme>"="<proxy-uri> | 68 // url-scheme = "http" | "https" | "ftp" | "socks" |
| 69 // | |
| 70 // scheme-proxies = [<url-scheme>"="]<proxy-uri-list> | |
| 71 // | |
| 72 // proxy-rules = scheme-proxies[";"<scheme-proxies>] | |
| 73 // | |
| 74 // Thus, the proxy-rules string should be a semicolon-separated list of | |
| 75 // ordered proxies that apply to a particular URL scheme. Unless specified, | |
| 76 // the proxy scheme for proxy-uris is assumed to be http. | |
| 77 // | |
| 78 // Some special cases: | |
| 79 // * If the scheme is omitted from the first proxy list, that list applies | |
| 80 // to all URL schemes and subsequent lists are ignored. | |
| 81 // * If a scheme is omitted from any proxy list after a list where a scheme | |
| 82 // has been provided, the list without a scheme is ignored. | |
| 83 // * If the scheme is set to 'socks', that sets a fallback list that | |
|
eroman
2013/03/06 23:26:32
nit: "If the scheme" --> "If the url-scheme"
marq_use_my_chromium_address
2013/03/07 00:34:29
Done.
| |
| 84 // to all otherwise unspecified url-schemes, however the default proxy- | |
| 85 // scheme for proxy urls in the 'socks' list is understood to be | |
| 86 // socks4:// if unspecified. | |
| 66 // | 87 // |
| 67 // For example: | 88 // For example: |
| 68 // "http=foopy:80;ftp=foopy2" -- use HTTP proxy "foopy:80" for http:// | 89 // "http=foopy:80;ftp=foopy2" -- use HTTP proxy "foopy:80" for http:// |
| 69 // URLs, and HTTP proxy "foopy2:80" for | 90 // URLs, and HTTP proxy "foopy2:80" for |
| 70 // ftp:// URLs. | 91 // ftp:// URLs. |
| 71 // "foopy:80" -- use HTTP proxy "foopy:80" for all URLs. | 92 // "foopy:80" -- use HTTP proxy "foopy:80" for all URLs. |
| 93 // "foopy:80,bar,direct://" -- use HTTP proxy "foopy:80" for all URLs, | |
| 94 // failing over to "bar" if "foopy:80" is | |
| 95 // unavailable, and after that using no | |
| 96 // proxy. | |
| 72 // "socks4://foopy" -- use SOCKS v4 proxy "foopy:1080" for all | 97 // "socks4://foopy" -- use SOCKS v4 proxy "foopy:1080" for all |
| 73 // URLs. | 98 // URLs. |
| 99 // "http=foop,socks5://bar.com -- use HTTP proxy "foopy" for http URLs, | |
| 100 // and fail over to the SOCKS5 proxy | |
| 101 // "bar.com" if "foop" is unavailable. | |
| 102 // "http=foopy,direct:// -- use HTTP proxy "foopy" for http URLs, | |
| 103 // and use no proxy if "foopy" is | |
| 104 // unavailable. | |
| 105 // "http=foopy;socks=foopy2 -- use HTTP proxy "foopy" for http URLs, | |
| 106 // and use socks4://foopy2 for all other | |
| 107 // URLs. | |
| 74 void ParseFromString(const std::string& proxy_rules); | 108 void ParseFromString(const std::string& proxy_rules); |
| 75 | 109 |
| 76 // Returns one of {&proxy_for_http, &proxy_for_https, &proxy_for_ftp, | 110 // Returns one of {&proxies_for_http, &proxies_for_https, &proxies_for_ftp, |
| 77 // &fallback_proxy}, or NULL if there is no proxy to use. | 111 // &fallback_proxies}, or NULL if there is no proxy to use. |
| 78 // Should only call this if the type is TYPE_PROXY_PER_SCHEME. | 112 // Should only call this if the type is TYPE_PROXY_PER_SCHEME. |
| 79 const ProxyServer* MapUrlSchemeToProxy(const std::string& url_scheme) const; | 113 const ProxyList* MapUrlSchemeToProxyList( |
| 114 const std::string& url_scheme) const; | |
| 80 | 115 |
| 81 // Returns true if |*this| describes the same configuration as |other|. | 116 // Returns true if |*this| describes the same configuration as |other|. |
| 82 bool Equals(const ProxyRules& other) const; | 117 bool Equals(const ProxyRules& other) const; |
| 83 | 118 |
| 84 // Exceptions for when not to use a proxy. | 119 // Exceptions for when not to use a proxy. |
| 85 ProxyBypassRules bypass_rules; | 120 ProxyBypassRules bypass_rules; |
| 86 | 121 |
| 87 // Reverse the meaning of |bypass_rules|. | 122 // Reverse the meaning of |bypass_rules|. |
| 88 bool reverse_bypass; | 123 bool reverse_bypass; |
| 89 | 124 |
| 90 Type type; | 125 Type type; |
| 91 | 126 |
| 92 // Set if |type| is TYPE_SINGLE_PROXY. | 127 // Set if |type| is TYPE_SINGLE_PROXY. |
| 93 ProxyServer single_proxy; | 128 ProxyList single_proxies; |
| 94 | 129 |
| 95 // Set if |type| is TYPE_PROXY_PER_SCHEME. | 130 // Set if |type| is TYPE_PROXY_PER_SCHEME. |
| 96 ProxyServer proxy_for_http; | 131 ProxyList proxies_for_http; |
| 97 ProxyServer proxy_for_https; | 132 ProxyList proxies_for_https; |
| 98 ProxyServer proxy_for_ftp; | 133 ProxyList proxies_for_ftp; |
| 99 | 134 |
| 100 // Used when there isn't a more specific per-scheme proxy server. | 135 // Used when a fallback has been defined and the url to be proxied doesn't |
| 101 ProxyServer fallback_proxy; | 136 // match any of the standard schemes. |
| 137 ProxyList fallback_proxies; | |
| 102 | 138 |
| 103 private: | 139 private: |
| 104 // Returns one of {&proxy_for_http, &proxy_for_https, &proxy_for_ftp} | 140 // Returns one of {&proxies_for_http, &proxies_for_https, &proxies_for_ftp} |
| 105 // or NULL if it is a scheme that we don't have a mapping | 141 // or NULL if it is a scheme that we don't have a mapping |
| 106 // for. Should only call this if the type is TYPE_PROXY_PER_SCHEME. | 142 // for. Should only call this if the type is TYPE_PROXY_PER_SCHEME. |
| 107 ProxyServer* MapUrlSchemeToProxyNoFallback(const std::string& scheme); | 143 ProxyList* MapUrlSchemeToProxyListNoFallback(const std::string& scheme); |
| 108 }; | 144 }; |
| 109 | 145 |
| 110 typedef int ID; | 146 typedef int ID; |
| 111 | 147 |
| 112 // Indicates an invalid proxy config. | 148 // Indicates an invalid proxy config. |
| 113 static const ID kInvalidConfigID = 0; | 149 static const ID kInvalidConfigID = 0; |
| 114 | 150 |
| 115 ProxyConfig(); | 151 ProxyConfig(); |
| 116 ProxyConfig(const ProxyConfig& config); | 152 ProxyConfig(const ProxyConfig& config); |
| 117 ~ProxyConfig(); | 153 ~ProxyConfig(); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 ProxyConfigSource source_; | 254 ProxyConfigSource source_; |
| 219 | 255 |
| 220 ID id_; | 256 ID id_; |
| 221 }; | 257 }; |
| 222 | 258 |
| 223 } // namespace net | 259 } // namespace net |
| 224 | 260 |
| 225 | 261 |
| 226 | 262 |
| 227 #endif // NET_PROXY_PROXY_CONFIG_H_ | 263 #endif // NET_PROXY_PROXY_CONFIG_H_ |
| OLD | NEW |