Chromium Code Reviews| 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 773d14c7042f1443b5c757196c84bec974f702cd..a27f290d94783b064b48ab2e065e62dd2c6aa518 100644 |
| --- a/components/data_reduction_proxy/common/data_reduction_proxy_headers.cc |
| +++ b/components/data_reduction_proxy/common/data_reduction_proxy_headers.cc |
| @@ -20,10 +20,35 @@ using net::ProxyService; |
| namespace data_reduction_proxy { |
| +bool GetDataReductionProxyActionValue( |
| + const net::HttpResponseHeaders* headers, |
| + const std::string& action_prefix, |
| + std::string* action_value) { |
| + DCHECK(action_prefix.size()); |
|
bengr
2014/07/16 19:23:56
DCHECK(!action_prefix.empty());
xingx
2014/07/16 21:22:33
Done.
|
| + void* iter = NULL; |
| + std::string value; |
| + std::string name = "chrome-proxy"; |
|
bengr
2014/07/16 19:23:56
Add an anonymous namespace above this namespace an
xingx
2014/07/16 21:22:33
Done.
|
| + |
| + while (headers->EnumerateHeader(&iter, name, &value)) { |
| + if (value.size() > action_prefix.size()) { |
| + if (LowerCaseEqualsASCII(value.begin(), |
| + value.begin() + action_prefix.size(), |
| + action_prefix.c_str()) && |
| + value[action_prefix.size()] == '=') { |
|
bengr
2014/07/16 19:23:56
I think it's better to add '=' to the prefix befor
xingx
2014/07/16 21:22:33
Done.
"enforce the last character is not '='", b
|
| + if (action_value) |
| + *action_value = value.substr(action_prefix.size() + 1); |
| + return true; |
| + } |
| + } |
| + } |
| + return false; |
| +} |
| + |
| bool GetDataReductionProxyBypassDuration( |
| const net::HttpResponseHeaders* headers, |
| const std::string& action_prefix, |
| base::TimeDelta* duration) { |
| + DCHECK(action_prefix.size()); |
| void* iter = NULL; |
| std::string value; |
| std::string name = "chrome-proxy"; |
| @@ -32,10 +57,12 @@ bool GetDataReductionProxyBypassDuration( |
| if (value.size() > action_prefix.size()) { |
| if (LowerCaseEqualsASCII(value.begin(), |
| value.begin() + action_prefix.size(), |
| - action_prefix.c_str())) { |
| + action_prefix.c_str()) && |
| + value[action_prefix.size()] == '=') { |
|
bengr
2014/07/16 19:23:56
See above comment. The loop logic shouldn't change
xingx
2014/07/16 21:22:33
Done.
xingx
2014/07/16 21:22:33
Done.
|
| int64 seconds; |
| if (!base::StringToInt64( |
| - StringPiece(value.begin() + action_prefix.size(), value.end()), |
| + StringPiece(value.begin() + action_prefix.size() + 1, |
| + value.end()), |
| &seconds) || seconds < 0) { |
| continue; // In case there is a well formed instruction. |
| } |
| @@ -63,20 +90,21 @@ bool GetDataReductionProxyInfo(const net::HttpResponseHeaders* headers, |
| // 'block' takes precedence over 'bypass', so look for it first. |
| // TODO(bengr): Reduce checks for 'block' and 'bypass' to a single loop. |
| if (GetDataReductionProxyBypassDuration( |
| - headers, "block=", &proxy_info->bypass_duration)) { |
| + headers, "block", &proxy_info->bypass_duration)) { |
| proxy_info->bypass_all = true; |
| return true; |
| } |
| // Next, look for 'bypass'. |
| if (GetDataReductionProxyBypassDuration( |
| - headers, "bypass=", &proxy_info->bypass_duration)) { |
| + headers, "bypass", &proxy_info->bypass_duration)) { |
| return true; |
| } |
| return false; |
| } |
| -bool HasDataReductionProxyViaHeader(const net::HttpResponseHeaders* headers) { |
| +bool HasDataReductionProxyViaHeader(const net::HttpResponseHeaders* headers, |
| + bool* is_the_last) { |
|
bengr
2014/07/16 19:23:56
change to has_intermediary.
xingx
2014/07/16 21:22:33
Done.
|
| const size_t kVersionSize = 4; |
| const char kDataReductionProxyViaValue[] = "Chrome-Compression-Proxy"; |
| size_t value_len = strlen(kDataReductionProxyViaValue); |
| @@ -88,8 +116,11 @@ bool HasDataReductionProxyViaHeader(const net::HttpResponseHeaders* headers) { |
| // 'Via: 1.1 Chrome-Compression-Proxy' |
| while (headers->EnumerateHeader(&iter, "via", &value)) { |
| if (value.size() >= kVersionSize + value_len && |
| - !value.compare(kVersionSize, value_len, kDataReductionProxyViaValue)) |
| + !value.compare(kVersionSize, value_len, kDataReductionProxyViaValue)) { |
| + if (is_the_last) |
| + *is_the_last = !(headers->EnumerateHeader(&iter, "via", &value)); |
| return true; |
| + } |
| } |
| // TODO(bengr): Remove deprecated header value. |
| @@ -97,8 +128,11 @@ bool HasDataReductionProxyViaHeader(const net::HttpResponseHeaders* headers) { |
| "1.1 Chrome Compression Proxy"; |
| iter = NULL; |
| while (headers->EnumerateHeader(&iter, "via", &value)) |
| - if (value == kDeprecatedDataReductionProxyViaValue) |
| + if (value == kDeprecatedDataReductionProxyViaValue) { |
| + if (is_the_last) |
| + *is_the_last = !(headers->EnumerateHeader(&iter, "via", &value)); |
| return true; |
| + } |
| return false; |
| } |
| @@ -121,7 +155,7 @@ GetDataReductionProxyBypassEventType( |
| // Fall back if a 500, 502 or 503 is returned. |
| return ProxyService::INTERNAL_SERVER_ERROR_BYPASS; |
| } |
| - if (!HasDataReductionProxyViaHeader(headers) && |
| + if (!HasDataReductionProxyViaHeader(headers, NULL) && |
| (headers->response_code() != net::HTTP_NOT_MODIFIED)) { |
| // A Via header might not be present in a 304. Since the goal of a 304 |
| // response is to minimize information transfer, a sender in general |