| 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 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1096     return lifetimes; | 1096     return lifetimes; | 
| 1097   } | 1097   } | 
| 1098 | 1098 | 
| 1099   // Our heuristic freshness estimate for this resource is 0 seconds, in | 1099   // Our heuristic freshness estimate for this resource is 0 seconds, in | 
| 1100   // accordance with common browser behaviour. However, stale-while-revalidate | 1100   // accordance with common browser behaviour. However, stale-while-revalidate | 
| 1101   // may still apply. | 1101   // may still apply. | 
| 1102   DCHECK_EQ(TimeDelta(), lifetimes.freshness); | 1102   DCHECK_EQ(TimeDelta(), lifetimes.freshness); | 
| 1103   return lifetimes; | 1103   return lifetimes; | 
| 1104 } | 1104 } | 
| 1105 | 1105 | 
| 1106 // From RFC 2616 section 13.2.3: | 1106 // From RFC 7234 section 4.2.3: | 
| 1107 // | 1107 // | 
| 1108 // Summary of age calculation algorithm, when a cache receives a response: | 1108 // The following data is used for the age calculation: | 
| 1109 // | 1109 // | 
| 1110 //   /* | 1110 //    age_value | 
| 1111 //    * age_value | 1111 // | 
| 1112 //    *      is the value of Age: header received by the cache with | 1112 //       The term "age_value" denotes the value of the Age header field | 
| 1113 //    *              this response. | 1113 //       (Section 5.1), in a form appropriate for arithmetic operation; or | 
| 1114 //    * date_value | 1114 //       0, if not available. | 
| 1115 //    *      is the value of the origin server's Date: header | 1115 // | 
| 1116 //    * request_time | 1116 //    date_value | 
| 1117 //    *      is the (local) time when the cache made the request | 1117 // | 
| 1118 //    *              that resulted in this cached response | 1118 //       The term "date_value" denotes the value of the Date header field, | 
| 1119 //    * response_time | 1119 //       in a form appropriate for arithmetic operations.  See Section | 
| 1120 //    *      is the (local) time when the cache received the | 1120 //       7.1.1.2 of [RFC7231] for the definition of the Date header field, | 
| 1121 //    *              response | 1121 //       and for requirements regarding responses without it. | 
| 1122 //    * now | 1122 // | 
| 1123 //    *      is the current (local) time | 1123 //    now | 
| 1124 //    */ | 1124 // | 
| 1125 //   apparent_age = max(0, response_time - date_value); | 1125 //       The term "now" means "the current value of the clock at the host | 
| 1126 //   corrected_received_age = max(apparent_age, age_value); | 1126 //       performing the calculation".  A host ought to use NTP ([RFC5905]) | 
| 1127 //   response_delay = response_time - request_time; | 1127 //       or some similar protocol to synchronize its clocks to Coordinated | 
| 1128 //   corrected_initial_age = corrected_received_age + response_delay; | 1128 //       Universal Time. | 
| 1129 //   resident_time = now - response_time; | 1129 // | 
| 1130 //   current_age   = corrected_initial_age + resident_time; | 1130 //    request_time | 
|  | 1131 // | 
|  | 1132 //       The current value of the clock at the host at the time the request | 
|  | 1133 //       resulting in the stored response was made. | 
|  | 1134 // | 
|  | 1135 //    response_time | 
|  | 1136 // | 
|  | 1137 //       The current value of the clock at the host at the time the | 
|  | 1138 //       response was received. | 
|  | 1139 // | 
|  | 1140 //    The age is then calculated as | 
|  | 1141 // | 
|  | 1142 //     apparent_age = max(0, response_time - date_value); | 
|  | 1143 //     response_delay = response_time - request_time; | 
|  | 1144 //     corrected_age_value = age_value + response_delay; | 
|  | 1145 //     corrected_initial_age = max(apparent_age, corrected_age_value); | 
|  | 1146 //     resident_time = now - response_time; | 
|  | 1147 //     current_age = corrected_initial_age + resident_time; | 
| 1131 // | 1148 // | 
| 1132 TimeDelta HttpResponseHeaders::GetCurrentAge(const Time& request_time, | 1149 TimeDelta HttpResponseHeaders::GetCurrentAge(const Time& request_time, | 
| 1133                                              const Time& response_time, | 1150                                              const Time& response_time, | 
| 1134                                              const Time& current_time) const { | 1151                                              const Time& current_time) const { | 
| 1135   // If there is no Date header, then assume that the server response was | 1152   // If there is no Date header, then assume that the server response was | 
| 1136   // generated at the time when we received the response. | 1153   // generated at the time when we received the response. | 
| 1137   Time date_value; | 1154   Time date_value; | 
| 1138   if (!GetDateValue(&date_value)) | 1155   if (!GetDateValue(&date_value)) | 
| 1139     date_value = response_time; | 1156     date_value = response_time; | 
| 1140 | 1157 | 
| 1141   // If there is no Age header, then assume age is zero.  GetAgeValue does not | 1158   // 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. | 1159   // modify its out param if the value does not exist. | 
| 1143   TimeDelta age_value; | 1160   TimeDelta age_value; | 
| 1144   GetAgeValue(&age_value); | 1161   GetAgeValue(&age_value); | 
| 1145 | 1162 | 
| 1146   TimeDelta apparent_age = std::max(TimeDelta(), response_time - date_value); | 1163   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; | 1164   TimeDelta response_delay = response_time - request_time; | 
| 1149   TimeDelta corrected_initial_age = corrected_received_age + response_delay; | 1165   TimeDelta corrected_age_value = age_value + response_delay; | 
|  | 1166   TimeDelta corrected_initial_age = std::max(apparent_age, corrected_age_value); | 
| 1150   TimeDelta resident_time = current_time - response_time; | 1167   TimeDelta resident_time = current_time - response_time; | 
| 1151   TimeDelta current_age = corrected_initial_age + resident_time; | 1168   TimeDelta current_age = corrected_initial_age + resident_time; | 
| 1152 | 1169 | 
| 1153   return current_age; | 1170   return current_age; | 
| 1154 } | 1171 } | 
| 1155 | 1172 | 
| 1156 bool HttpResponseHeaders::GetMaxAgeValue(TimeDelta* result) const { | 1173 bool HttpResponseHeaders::GetMaxAgeValue(TimeDelta* result) const { | 
| 1157   return GetCacheControlDirective("max-age", result); | 1174   return GetCacheControlDirective("max-age", result); | 
| 1158 } | 1175 } | 
| 1159 | 1176 | 
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1468   return true; | 1485   return true; | 
| 1469 } | 1486 } | 
| 1470 | 1487 | 
| 1471 bool HttpResponseHeaders::IsChunkEncoded() const { | 1488 bool HttpResponseHeaders::IsChunkEncoded() const { | 
| 1472   // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. | 1489   // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. | 
| 1473   return GetHttpVersion() >= HttpVersion(1, 1) && | 1490   return GetHttpVersion() >= HttpVersion(1, 1) && | 
| 1474       HasHeaderValue("Transfer-Encoding", "chunked"); | 1491       HasHeaderValue("Transfer-Encoding", "chunked"); | 
| 1475 } | 1492 } | 
| 1476 | 1493 | 
| 1477 }  // namespace net | 1494 }  // namespace net | 
| OLD | NEW | 
|---|