| OLD | NEW |
| 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 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 DCHECK(headers); | 53 DCHECK(headers); |
| 54 DCHECK(!action_prefix.empty()); | 54 DCHECK(!action_prefix.empty()); |
| 55 // A valid action does not include a trailing '='. | 55 // A valid action does not include a trailing '='. |
| 56 DCHECK(action_prefix[action_prefix.size() - 1] != kActionValueDelimiter); | 56 DCHECK(action_prefix[action_prefix.size() - 1] != kActionValueDelimiter); |
| 57 void* iter = NULL; | 57 void* iter = NULL; |
| 58 std::string value; | 58 std::string value; |
| 59 std::string prefix = action_prefix + kActionValueDelimiter; | 59 std::string prefix = action_prefix + kActionValueDelimiter; |
| 60 | 60 |
| 61 while (headers->EnumerateHeader(&iter, kChromeProxyHeader, &value)) { | 61 while (headers->EnumerateHeader(&iter, kChromeProxyHeader, &value)) { |
| 62 if (value.size() > prefix.size()) { | 62 if (value.size() > prefix.size()) { |
| 63 if (base::LowerCaseEqualsASCII(value.begin(), | 63 if (LowerCaseEqualsASCII(value.begin(), |
| 64 value.begin() + prefix.size(), | 64 value.begin() + prefix.size(), |
| 65 prefix.c_str())) { | 65 prefix.c_str())) { |
| 66 if (action_value) | 66 if (action_value) |
| 67 *action_value = value.substr(prefix.size()); | 67 *action_value = value.substr(prefix.size()); |
| 68 return true; | 68 return true; |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 return false; | 72 return false; |
| 73 } | 73 } |
| 74 | 74 |
| 75 bool ParseHeadersAndSetBypassDuration(const net::HttpResponseHeaders* headers, | 75 bool ParseHeadersAndSetBypassDuration(const net::HttpResponseHeaders* headers, |
| 76 const std::string& action_prefix, | 76 const std::string& action_prefix, |
| 77 base::TimeDelta* bypass_duration) { | 77 base::TimeDelta* bypass_duration) { |
| 78 DCHECK(headers); | 78 DCHECK(headers); |
| 79 DCHECK(!action_prefix.empty()); | 79 DCHECK(!action_prefix.empty()); |
| 80 // A valid action does not include a trailing '='. | 80 // A valid action does not include a trailing '='. |
| 81 DCHECK(action_prefix[action_prefix.size() - 1] != kActionValueDelimiter); | 81 DCHECK(action_prefix[action_prefix.size() - 1] != kActionValueDelimiter); |
| 82 void* iter = NULL; | 82 void* iter = NULL; |
| 83 std::string value; | 83 std::string value; |
| 84 std::string prefix = action_prefix + kActionValueDelimiter; | 84 std::string prefix = action_prefix + kActionValueDelimiter; |
| 85 | 85 |
| 86 while (headers->EnumerateHeader(&iter, kChromeProxyHeader, &value)) { | 86 while (headers->EnumerateHeader(&iter, kChromeProxyHeader, &value)) { |
| 87 if (value.size() > prefix.size()) { | 87 if (value.size() > prefix.size()) { |
| 88 if (base::LowerCaseEqualsASCII(value.begin(), | 88 if (LowerCaseEqualsASCII(value.begin(), |
| 89 value.begin() + prefix.size(), | 89 value.begin() + prefix.size(), |
| 90 prefix.c_str())) { | 90 prefix.c_str())) { |
| 91 int64 seconds; | 91 int64 seconds; |
| 92 if (!base::StringToInt64( | 92 if (!base::StringToInt64( |
| 93 StringPiece(value.begin() + prefix.size(), value.end()), | 93 StringPiece(value.begin() + prefix.size(), value.end()), |
| 94 &seconds) || seconds < 0) { | 94 &seconds) || seconds < 0) { |
| 95 continue; // In case there is a well formed instruction. | 95 continue; // In case there is a well formed instruction. |
| 96 } | 96 } |
| 97 if (seconds != 0) { | 97 if (seconds != 0) { |
| 98 *bypass_duration = TimeDelta::FromSeconds(seconds); | 98 *bypass_duration = TimeDelta::FromSeconds(seconds); |
| 99 } else { | 99 } else { |
| 100 // Server deferred to us to choose a duration. Default to a random | 100 // Server deferred to us to choose a duration. Default to a random |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 const net::HttpResponseHeaders* headers, | 262 const net::HttpResponseHeaders* headers, |
| 263 std::vector<std::string>* values) { | 263 std::vector<std::string>* values) { |
| 264 DCHECK(values); | 264 DCHECK(values); |
| 265 std::string chrome_proxy_fingerprint_prefix = std::string( | 265 std::string chrome_proxy_fingerprint_prefix = std::string( |
| 266 kChromeProxyActionFingerprintChromeProxy) + kActionValueDelimiter; | 266 kChromeProxyActionFingerprintChromeProxy) + kActionValueDelimiter; |
| 267 | 267 |
| 268 std::string value; | 268 std::string value; |
| 269 void* iter = NULL; | 269 void* iter = NULL; |
| 270 while (headers->EnumerateHeader(&iter, kChromeProxyHeader, &value)) { | 270 while (headers->EnumerateHeader(&iter, kChromeProxyHeader, &value)) { |
| 271 if (value.size() > chrome_proxy_fingerprint_prefix.size()) { | 271 if (value.size() > chrome_proxy_fingerprint_prefix.size()) { |
| 272 if (base::LowerCaseEqualsASCII( | 272 if (LowerCaseEqualsASCII( |
| 273 value.begin(), | 273 value.begin(), |
| 274 value.begin() + chrome_proxy_fingerprint_prefix.size(), | 274 value.begin() + chrome_proxy_fingerprint_prefix.size(), |
| 275 chrome_proxy_fingerprint_prefix.c_str())) { | 275 chrome_proxy_fingerprint_prefix.c_str())) { |
| 276 continue; | 276 continue; |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 values->push_back(value); | 279 values->push_back(value); |
| 280 } | 280 } |
| 281 } | 281 } |
| 282 | 282 |
| 283 } // namespace data_reduction_proxy | 283 } // namespace data_reduction_proxy |
| OLD | NEW |