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/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" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // Next, look for 'bypass'. | 71 // Next, look for 'bypass'. |
72 if (GetDataReductionProxyBypassDuration( | 72 if (GetDataReductionProxyBypassDuration( |
73 headers, "bypass=", &proxy_info->bypass_duration)) { | 73 headers, "bypass=", &proxy_info->bypass_duration)) { |
74 return true; | 74 return true; |
75 } | 75 } |
76 return false; | 76 return false; |
77 } | 77 } |
78 | 78 |
79 bool HasDataReductionProxyViaHeader(const net::HttpResponseHeaders* headers) { | 79 bool HasDataReductionProxyViaHeader(const net::HttpResponseHeaders* headers) { |
80 const size_t kVersionSize = 4; | 80 const size_t kVersionSize = 4; |
81 const char kDataReductionProxyViaValue[] = "Chrome-Compression-Proxy"; | |
82 size_t value_len = strlen(kDataReductionProxyViaValue); | 81 size_t value_len = strlen(kDataReductionProxyViaValue); |
83 void* iter = NULL; | 82 void* iter = NULL; |
84 std::string value; | 83 std::string value; |
85 | 84 |
86 // Case-sensitive comparison of |value|. Assumes the received protocol and the | 85 // Case-sensitive comparison of |value|. Assumes the received protocol and the |
87 // space following it are always |kVersionSize| characters. E.g., | 86 // space following it are always |kVersionSize| characters. E.g., |
88 // 'Via: 1.1 Chrome-Compression-Proxy' | 87 // 'Via: 1.1 Chrome-Compression-Proxy' |
89 while (headers->EnumerateHeader(&iter, "via", &value)) { | 88 while (headers->EnumerateHeader(&iter, "via", &value)) { |
90 if (value.size() >= kVersionSize + value_len && | 89 if (value.size() >= kVersionSize + value_len && |
91 !value.compare(kVersionSize, value_len, kDataReductionProxyViaValue)) | 90 !value.compare(kVersionSize, value_len, kDataReductionProxyViaValue)) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 headers->response_code() < net::HTTP_INTERNAL_SERVER_ERROR) { | 133 headers->response_code() < net::HTTP_INTERNAL_SERVER_ERROR) { |
135 return ProxyService::PROXY_4XX_BYPASS; | 134 return ProxyService::PROXY_4XX_BYPASS; |
136 } | 135 } |
137 return ProxyService::MISSING_VIA_HEADER; | 136 return ProxyService::MISSING_VIA_HEADER; |
138 } | 137 } |
139 // There is no bypass event. | 138 // There is no bypass event. |
140 return ProxyService::BYPASS_EVENT_TYPE_MAX; | 139 return ProxyService::BYPASS_EVENT_TYPE_MAX; |
141 } | 140 } |
142 | 141 |
143 } // namespace data_reduction_proxy | 142 } // namespace data_reduction_proxy |
OLD | NEW |