Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // The rules for header parsing were borrowed from Firefox: | 5 // The rules for header parsing were borrowed from Firefox: |
| 6 // http://lxr.mozilla.org/seamonkey/source/netwerk/protocol/http/src/nsHttpRespo nseHead.cpp | 6 // http://lxr.mozilla.org/seamonkey/source/netwerk/protocol/http/src/nsHttpRespo nseHead.cpp |
| 7 // The rules for parsing content-types were also borrowed from Firefox: | 7 // The rules for parsing content-types were also borrowed from Firefox: |
| 8 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 | 8 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 |
| 9 | 9 |
| 10 #include "net/http/http_response_headers.h" | 10 #include "net/http/http_response_headers.h" |
| (...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1121 // * response | 1121 // * response |
| 1122 // * now | 1122 // * now |
| 1123 // * is the current (local) time | 1123 // * is the current (local) time |
| 1124 // */ | 1124 // */ |
| 1125 // apparent_age = max(0, response_time - date_value); | 1125 // apparent_age = max(0, response_time - date_value); |
| 1126 // corrected_received_age = max(apparent_age, age_value); | 1126 // corrected_received_age = max(apparent_age, age_value); |
| 1127 // response_delay = response_time - request_time; | 1127 // response_delay = response_time - request_time; |
| 1128 // corrected_initial_age = corrected_received_age + response_delay; | 1128 // corrected_initial_age = corrected_received_age + response_delay; |
| 1129 // resident_time = now - response_time; | 1129 // resident_time = now - response_time; |
| 1130 // current_age = corrected_initial_age + resident_time; | 1130 // current_age = corrected_initial_age + resident_time; |
| 1131 // | 1131 // |
|
mmenke
2017/01/19 16:11:18
I assume this comment needs to be updated, too (An
billyjay
2017/01/20 19:23:26
Done.
| |
| 1132 TimeDelta HttpResponseHeaders::GetCurrentAge(const Time& request_time, | 1132 TimeDelta HttpResponseHeaders::GetCurrentAge(const Time& request_time, |
| 1133 const Time& response_time, | 1133 const Time& response_time, |
| 1134 const Time& current_time) const { | 1134 const Time& current_time) const { |
| 1135 // If there is no Date header, then assume that the server response was | 1135 // If there is no Date header, then assume that the server response was |
| 1136 // generated at the time when we received the response. | 1136 // generated at the time when we received the response. |
| 1137 Time date_value; | 1137 Time date_value; |
| 1138 if (!GetDateValue(&date_value)) | 1138 if (!GetDateValue(&date_value)) |
| 1139 date_value = response_time; | 1139 date_value = response_time; |
| 1140 | 1140 |
| 1141 // If there is no Age header, then assume age is zero. GetAgeValue does not | 1141 // If there is no Age header, then assume age is zero. GetAgeValue does not |
| 1142 // modify its out param if the value does not exist. | 1142 // modify its out param if the value does not exist. |
| 1143 TimeDelta age_value; | 1143 TimeDelta age_value; |
| 1144 GetAgeValue(&age_value); | 1144 GetAgeValue(&age_value); |
| 1145 | 1145 |
| 1146 TimeDelta apparent_age = std::max(TimeDelta(), response_time - date_value); | 1146 TimeDelta apparent_age = std::max(TimeDelta(), response_time - date_value); |
| 1147 TimeDelta corrected_received_age = std::max(apparent_age, age_value); | |
| 1148 TimeDelta response_delay = response_time - request_time; | 1147 TimeDelta response_delay = response_time - request_time; |
| 1149 TimeDelta corrected_initial_age = corrected_received_age + response_delay; | 1148 TimeDelta corrected_age_value = age_value + response_delay; |
| 1149 TimeDelta corrected_initial_age = std::max(apparent_age, corrected_age_value); | |
|
mmenke
2017/01/19 16:11:18
We should have a test for the changed behavior.
billyjay
2017/01/20 19:23:26
Done.
| |
| 1150 TimeDelta resident_time = current_time - response_time; | 1150 TimeDelta resident_time = current_time - response_time; |
| 1151 TimeDelta current_age = corrected_initial_age + resident_time; | 1151 TimeDelta current_age = corrected_initial_age + resident_time; |
| 1152 | 1152 |
| 1153 return current_age; | 1153 return current_age; |
| 1154 } | 1154 } |
| 1155 | 1155 |
| 1156 bool HttpResponseHeaders::GetMaxAgeValue(TimeDelta* result) const { | 1156 bool HttpResponseHeaders::GetMaxAgeValue(TimeDelta* result) const { |
| 1157 return GetCacheControlDirective("max-age", result); | 1157 return GetCacheControlDirective("max-age", result); |
| 1158 } | 1158 } |
| 1159 | 1159 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1468 return true; | 1468 return true; |
| 1469 } | 1469 } |
| 1470 | 1470 |
| 1471 bool HttpResponseHeaders::IsChunkEncoded() const { | 1471 bool HttpResponseHeaders::IsChunkEncoded() const { |
| 1472 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. | 1472 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. |
| 1473 return GetHttpVersion() >= HttpVersion(1, 1) && | 1473 return GetHttpVersion() >= HttpVersion(1, 1) && |
| 1474 HasHeaderValue("Transfer-Encoding", "chunked"); | 1474 HasHeaderValue("Transfer-Encoding", "chunked"); |
| 1475 } | 1475 } |
| 1476 | 1476 |
| 1477 } // namespace net | 1477 } // namespace net |
| OLD | NEW |