Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(913)

Unified Diff: net/proxy/proxy_config.cc

Issue 57011: Extract the parsing of proxy rules to ProxyConfig::ProxyRules, and unit-test.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: address wtc's second batch of comments -- second try, got rietveld 500 before... Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/proxy/proxy_config.h ('k') | net/proxy/proxy_config_service_fixed.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/proxy/proxy_config.cc
===================================================================
--- net/proxy/proxy_config.cc (revision 12729)
+++ net/proxy/proxy_config.cc (working copy)
@@ -4,6 +4,9 @@
#include "net/proxy/proxy_config.h"
+#include "base/string_tokenizer.h"
+#include "base/string_util.h"
+
namespace net {
// static
@@ -25,4 +28,55 @@
proxy_bypass_local_names == other.proxy_bypass_local_names;
}
+void ProxyConfig::ProxyRules::ParseFromString(const std::string& proxy_rules) {
+ // Reset.
+ type = TYPE_NO_RULES;
+ single_proxy = ProxyServer();
+ proxy_for_http = ProxyServer();
+ proxy_for_https = ProxyServer();
+ proxy_for_ftp = ProxyServer();
+
+ StringTokenizer proxy_server_list(proxy_rules, ";");
+ while (proxy_server_list.GetNext()) {
+ StringTokenizer proxy_server_for_scheme(
+ proxy_server_list.token_begin(), proxy_server_list.token_end(), "=");
+
+ while (proxy_server_for_scheme.GetNext()) {
+ std::string url_scheme = proxy_server_for_scheme.token();
+
+ // If we fail to get the proxy server here, it means that
+ // this is a regular proxy server configuration, i.e. proxies
+ // are not configured per protocol.
+ 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;
+ }
+
+ // Trim whitespace off the url scheme.
+ TrimWhitespaceASCII(url_scheme, TRIM_ALL, &url_scheme);
+
+ // 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());
+ }
+ }
+}
+
+const ProxyServer* ProxyConfig::ProxyRules::MapSchemeToProxy(
+ const std::string& scheme) const {
+ DCHECK(type == TYPE_PROXY_PER_SCHEME);
+ if (scheme == "http")
+ return &proxy_for_http;
+ if (scheme == "https")
+ return &proxy_for_https;
+ if (scheme == "ftp")
+ return &proxy_for_ftp;
+ return NULL; // No mapping for this scheme.
+}
+
} // namespace net
« no previous file with comments | « net/proxy/proxy_config.h ('k') | net/proxy/proxy_config_service_fixed.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698