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

Unified Diff: components/data_reduction_proxy/common/data_reduction_proxy_headers.cc

Issue 467823002: Added support for 'Chrome-Proxy: block-once' header (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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: components/data_reduction_proxy/common/data_reduction_proxy_headers.cc
diff --git a/components/data_reduction_proxy/common/data_reduction_proxy_headers.cc b/components/data_reduction_proxy/common/data_reduction_proxy_headers.cc
index c68d3e6c915203a1b1173bba9d65e82e78031016..532ccfac8aef640dee0b24a0810c759bd178a9c7 100644
--- a/components/data_reduction_proxy/common/data_reduction_proxy_headers.cc
+++ b/components/data_reduction_proxy/common/data_reduction_proxy_headers.cc
@@ -23,6 +23,7 @@ namespace {
const char kChromeProxyHeader[] = "chrome-proxy";
const char kActionValueDelimiter = '=';
+const char kChromeProxyActionBlockOnce[] = "block-once";
const char kChromeProxyActionBlock[] = "block";
const char kChromeProxyActionBypass[] = "bypass";
@@ -42,6 +43,7 @@ base::TimeDelta GetDefaultBypassDuration() {
base::TimeDelta::FromMinutes(5).InMilliseconds());
return TimeDelta::FromMilliseconds(delta_ms);
}
+
} // namespace
namespace data_reduction_proxy {
@@ -111,7 +113,7 @@ bool ParseHeadersAndSetBypassDuration(const net::HttpResponseHeaders* headers,
bool ParseHeadersAndSetProxyInfo(const net::HttpResponseHeaders* headers,
DataReductionProxyInfo* proxy_info) {
DCHECK(proxy_info);
- proxy_info->bypass_all = false;
+
// Support header of the form Chrome-Proxy: bypass|block=<duration>, where
// <duration> is the number of seconds to wait before retrying
// the proxy. If the duration is 0, then the default proxy retry delay
@@ -120,19 +122,37 @@ bool ParseHeadersAndSetProxyInfo(const net::HttpResponseHeaders* headers,
// proxy, whereas 'block' instructs Chrome to bypass all available data
// reduction proxies.
- // 'block' takes precedence over 'bypass', so look for it first.
+ // 'block' takes precedence over 'bypass' and 'block-once', so look for it
+ // first.
// TODO(bengr): Reduce checks for 'block' and 'bypass' to a single loop.
if (ParseHeadersAndSetBypassDuration(
headers, kChromeProxyActionBlock, &proxy_info->bypass_duration)) {
proxy_info->bypass_all = true;
+ proxy_info->mark_proxies_as_bad = true;
return true;
}
// Next, look for 'bypass'.
if (ParseHeadersAndSetBypassDuration(
headers, kChromeProxyActionBypass, &proxy_info->bypass_duration)) {
+ proxy_info->bypass_all = false;
+ proxy_info->mark_proxies_as_bad = true;
return true;
}
+
+ // Lastly, look for 'block-once'. 'block-once' instructs Chrome to retry the
+ // current request (if it's idempotent), bypassing all available data
+ // reduction proxies. Unlike 'block', 'block-once' does not cause data
+ // reduction proxies to be bypassed for an extended period of time;
+ // 'block-once' only affects the retry of the current request.
+ if (headers->HasHeaderValue(kChromeProxyHeader,
bengr 2014/08/12 20:57:10 If we believe that this will become the dominant i
sclittle 2014/08/12 21:24:43 I'm not certain what the priorities should be. The
+ kChromeProxyActionBlockOnce)) {
+ proxy_info->bypass_all = true;
+ proxy_info->mark_proxies_as_bad = false;
+ proxy_info->bypass_duration = TimeDelta();
+ return true;
+ }
+
return false;
}
@@ -179,16 +199,17 @@ DataReductionProxyBypassType GetDataReductionProxyBypassType(
if (ParseHeadersAndSetProxyInfo(headers, data_reduction_proxy_info)) {
// A chrome-proxy response header is only present in a 502. For proper
// reporting, this check must come before the 5xx checks below.
+ if (!data_reduction_proxy_info->mark_proxies_as_bad)
+ return BYPASS_EVENT_TYPE_CURRENT;
+
const TimeDelta& duration = data_reduction_proxy_info->bypass_duration;
- // bypass=0 means bypass for a random duration between 1 to 5 minutes
- if (duration == TimeDelta())
- return BYPASS_EVENT_TYPE_MEDIUM;
if (duration <= TimeDelta::FromSeconds(kShortBypassMaxSeconds))
return BYPASS_EVENT_TYPE_SHORT;
if (duration <= TimeDelta::FromSeconds(kMediumBypassMaxSeconds))
return BYPASS_EVENT_TYPE_MEDIUM;
return BYPASS_EVENT_TYPE_LONG;
}
+ data_reduction_proxy_info->mark_proxies_as_bad = true;
bengr 2014/08/12 20:57:11 Please add a comment to explain why this gets set
sclittle 2014/08/12 21:24:43 Done.
data_reduction_proxy_info->bypass_duration = GetDefaultBypassDuration();
// Fall back if a 500, 502 or 503 is returned.
if (headers->response_code() == net::HTTP_INTERNAL_SERVER_ERROR)

Powered by Google App Engine
This is Rietveld 408576698