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

Side by Side Diff: components/data_reduction_proxy/common/data_reduction_proxy_headers.cc

Issue 338483002: Chrome Participated Tamper Detect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" 5 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "net/http/http_response_headers.h" 13 #include "net/http/http_response_headers.h"
14 #include "net/http/http_status_code.h" 14 #include "net/http/http_status_code.h"
15 #include "net/proxy/proxy_service.h" 15 #include "net/proxy/proxy_service.h"
16 16
17 using base::StringPiece; 17 using base::StringPiece;
18 using base::TimeDelta; 18 using base::TimeDelta;
19 using net::ProxyService; 19 using net::ProxyService;
20 20
21 namespace data_reduction_proxy { 21 namespace data_reduction_proxy {
22 22
23 const char* kDataReductionProxyViaValues[] = {"Chrome-Compression-Proxy",
bengr 2014/07/11 18:22:49 I don't know why you added this here, but make the
bengr 2014/07/11 18:22:49 Also, move this into an anonymous namespace.
24 "Chrome Compression Proxy"};
25
23 bool GetDataReductionProxyBypassDuration( 26 bool GetDataReductionProxyBypassDuration(
24 const net::HttpResponseHeaders* headers, 27 const net::HttpResponseHeaders* headers,
25 const std::string& action_prefix, 28 const std::string& action_prefix,
26 base::TimeDelta* duration) { 29 base::TimeDelta* duration) {
27 void* iter = NULL; 30 void* iter = NULL;
28 std::string value; 31 std::string value;
29 std::string name = "chrome-proxy"; 32 std::string name = "chrome-proxy";
30 33
31 while (headers->EnumerateHeader(&iter, name, &value)) { 34 while (headers->EnumerateHeader(&iter, name, &value)) {
32 if (value.size() > action_prefix.size()) { 35 if (value.size() > action_prefix.size()) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // Next, look for 'bypass'. 74 // Next, look for 'bypass'.
72 if (GetDataReductionProxyBypassDuration( 75 if (GetDataReductionProxyBypassDuration(
73 headers, "bypass=", &proxy_info->bypass_duration)) { 76 headers, "bypass=", &proxy_info->bypass_duration)) {
74 return true; 77 return true;
75 } 78 }
76 return false; 79 return false;
77 } 80 }
78 81
79 bool HasDataReductionProxyViaHeader(const net::HttpResponseHeaders* headers) { 82 bool HasDataReductionProxyViaHeader(const net::HttpResponseHeaders* headers) {
80 const size_t kVersionSize = 4; 83 const size_t kVersionSize = 4;
81 const char kDataReductionProxyViaValue[] = "Chrome-Compression-Proxy"; 84 size_t value_len = strlen(kDataReductionProxyViaValues[0]);
82 size_t value_len = strlen(kDataReductionProxyViaValue);
83 void* iter = NULL; 85 void* iter = NULL;
84 std::string value; 86 std::string value;
85 87
86 // Case-sensitive comparison of |value|. Assumes the received protocol and the 88 // Case-sensitive comparison of |value|. Assumes the received protocol and the
87 // space following it are always |kVersionSize| characters. E.g., 89 // space following it are always |kVersionSize| characters. E.g.,
88 // 'Via: 1.1 Chrome-Compression-Proxy' 90 // 'Via: 1.1 Chrome-Compression-Proxy'
89 while (headers->EnumerateHeader(&iter, "via", &value)) { 91 while (headers->EnumerateHeader(&iter, "via", &value)) {
90 if (value.size() >= kVersionSize + value_len && 92 if (value.size() >= kVersionSize + value_len &&
91 !value.compare(kVersionSize, value_len, kDataReductionProxyViaValue)) 93 !value.compare(kVersionSize, value_len,
94 kDataReductionProxyViaValues[0]))
92 return true; 95 return true;
93 } 96 }
94 97
95 // TODO(bengr): Remove deprecated header value. 98 // TODO(bengr): Remove deprecated header value.
96 const char kDeprecatedDataReductionProxyViaValue[] = 99 const char kDeprecatedDataReductionProxyViaValue[] =
97 "1.1 Chrome Compression Proxy"; 100 "1.1 Chrome Compression Proxy";
bengr 2014/07/11 18:22:49 This should be changed too.
98 iter = NULL; 101 iter = NULL;
99 while (headers->EnumerateHeader(&iter, "via", &value)) 102 while (headers->EnumerateHeader(&iter, "via", &value))
100 if (value == kDeprecatedDataReductionProxyViaValue) 103 if (value == kDeprecatedDataReductionProxyViaValue)
101 return true; 104 return true;
102 105
103 return false; 106 return false;
104 } 107 }
105 108
106 net::ProxyService::DataReductionProxyBypassEventType 109 net::ProxyService::DataReductionProxyBypassEventType
107 GetDataReductionProxyBypassEventType( 110 GetDataReductionProxyBypassEventType(
(...skipping 26 matching lines...) Expand all
134 headers->response_code() < net::HTTP_INTERNAL_SERVER_ERROR) { 137 headers->response_code() < net::HTTP_INTERNAL_SERVER_ERROR) {
135 return ProxyService::PROXY_4XX_BYPASS; 138 return ProxyService::PROXY_4XX_BYPASS;
136 } 139 }
137 return ProxyService::MISSING_VIA_HEADER; 140 return ProxyService::MISSING_VIA_HEADER;
138 } 141 }
139 // There is no bypass event. 142 // There is no bypass event.
140 return ProxyService::BYPASS_EVENT_TYPE_MAX; 143 return ProxyService::BYPASS_EVENT_TYPE_MAX;
141 } 144 }
142 145
143 } // namespace data_reduction_proxy 146 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698