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 | 8 |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 bool ParseHeadersAndSetBypassDuration(const net::HttpResponseHeaders* headers, | 38 bool ParseHeadersAndSetBypassDuration(const net::HttpResponseHeaders* headers, |
39 const std::string& action_prefix, | 39 const std::string& action_prefix, |
40 base::TimeDelta* bypass_duration) { | 40 base::TimeDelta* bypass_duration) { |
41 void* iter = NULL; | 41 void* iter = NULL; |
42 std::string value; | 42 std::string value; |
43 std::string name = "chrome-proxy"; | 43 std::string name = "chrome-proxy"; |
44 | 44 |
45 while (headers->EnumerateHeader(&iter, name, &value)) { | 45 while (headers->EnumerateHeader(&iter, name, &value)) { |
46 if (value.size() > action_prefix.size()) { | 46 if (value.size() > action_prefix.size()) { |
47 if (LowerCaseEqualsASCII(value.begin(), | 47 if (base::LowerCaseEqualsASCII(value.begin(), |
48 value.begin() + action_prefix.size(), | 48 value.begin() + action_prefix.size(), |
49 action_prefix.c_str())) { | 49 action_prefix.c_str())) { |
50 int64 seconds; | 50 int64 seconds; |
51 if (!base::StringToInt64( | 51 if (!base::StringToInt64( |
52 StringPiece(value.begin() + action_prefix.size(), value.end()), | 52 StringPiece(value.begin() + action_prefix.size(), value.end()), |
53 &seconds) || seconds < 0) { | 53 &seconds) || seconds < 0) { |
54 continue; // In case there is a well formed instruction. | 54 continue; // In case there is a well formed instruction. |
55 } | 55 } |
56 if (seconds != 0) { | 56 if (seconds != 0) { |
57 *bypass_duration = TimeDelta::FromSeconds(seconds); | 57 *bypass_duration = TimeDelta::FromSeconds(seconds); |
58 } else { | 58 } else { |
59 // Server deferred to us to choose a duration. Default to a random | 59 // Server deferred to us to choose a duration. Default to a random |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 headers->response_code() < net::HTTP_INTERNAL_SERVER_ERROR) { | 164 headers->response_code() < net::HTTP_INTERNAL_SERVER_ERROR) { |
165 return ProxyService::MISSING_VIA_HEADER_4XX; | 165 return ProxyService::MISSING_VIA_HEADER_4XX; |
166 } | 166 } |
167 return ProxyService::MISSING_VIA_HEADER_OTHER; | 167 return ProxyService::MISSING_VIA_HEADER_OTHER; |
168 } | 168 } |
169 // There is no bypass event. | 169 // There is no bypass event. |
170 return ProxyService::BYPASS_EVENT_TYPE_MAX; | 170 return ProxyService::BYPASS_EVENT_TYPE_MAX; |
171 } | 171 } |
172 | 172 |
173 } // namespace data_reduction_proxy | 173 } // namespace data_reduction_proxy |
OLD | NEW |