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

Unified Diff: chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.cc

Issue 30883003: Simple fallback implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patched
Patch Set: Created 7 years, 2 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
Index: chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.cc
diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.cc b/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.cc
index 2c23fbff129edd09db973256d4673c68c5d3668a..e5ae091d2bc9c08177f0bbec76ab87520693b90f 100644
--- a/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.cc
+++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.cc
@@ -55,6 +55,21 @@ enum {
NUM_SPDY_PROXY_AUTH_STATE
};
+// Generates a PAC proxy string component, including trailing semicolon and
+// space, for |origin|. Eg:
+// "http://foo.com/" -> "HTTP foo.com:80; "
+// "https://bar.com:10443" -> "HTTPS bar.coom:10443; "
+// The returned strings are suitable for concatenating into a PAC string.
+// If |origin| is empty, returns an empty string.
+std::string ProtocolAndHostForPACString(const std::string& origin) {
+ if (origin.empty()) {
+ return std::string();
+ }
+ GURL url = GURL(origin);
+ std::string protocol = url.SchemeIsSecure() ? "HTTPS " : "HTTP ";
+ return protocol + net::HostPortPair::FromURL(url).ToString() + "; ";
+}
+
} // namespace
DataReductionProxySettingsAndroid::DataReductionProxySettingsAndroid(
@@ -260,19 +275,18 @@ std::string DataReductionProxySettingsAndroid::GetProxyPacScript() {
"(" + JoinString(pac_bypass_rules_, ") || (") + ")";
// Generate a proxy PAC that falls back to direct loading when the proxy is
- // unavailable and only process HTTP traffic. (With a statically configured
- // proxy, proxy failures will simply result in a connection error presented to
- // users.)
+ // unavailable and only process HTTP traffic.
- std::string proxy_host =
- DataReductionProxySettings::GetDataReductionProxyOriginHostPort();
+ std::string proxy_host = ProtocolAndHostForPACString(
+ DataReductionProxySettings::GetDataReductionProxyOrigin());
+ std::string fallback_host = ProtocolAndHostForPACString(
+ DataReductionProxySettings::GetDataReductionProxyFallback());
std::string pac = "function FindProxyForURL(url, host) {"
" if (" + bypass_clause + ") {"
" return 'DIRECT';"
" } "
" if (url.substring(0, 5) == 'http:') {"
- " return 'HTTPS " + proxy_host +
- "; DIRECT';"
+ " return '" + proxy_host + fallback_host + "DIRECT';"
" }"
" return 'DIRECT';"
"}";

Powered by Google App Engine
This is Rietveld 408576698