Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Unified Diff: net/http/http_response_headers.cc

Issue 154243006: Add GetExpirationTimes() to HttpResponseHeader. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_response_headers.h ('k') | net/http/http_response_headers_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_response_headers.cc
diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc
index 2d74b38efc767f13bcaacdbfc811970de8f2946e..ab1396cc22992a5f28f0a071151dd41dc49e6697 100644
--- a/net/http/http_response_headers.cc
+++ b/net/http/http_response_headers.cc
@@ -905,18 +905,80 @@ bool HttpResponseHeaders::IsRedirectResponseCode(int response_code) {
//
// response_is_fresh = (freshness_lifetime > current_age)
//
+// Into this equation, we substitute |current_age = now - freshness_origin|,
darin (slow to review) 2014/03/26 16:16:27 what is "freshness_origin"?
gavinp 2016/04/29 15:04:51 Removed this.
+// giving:
+//
+// response_is_fresh = (freshness_lifetime > now - freshness_origin)
+//
+// response_is_fresh = (freshness_lifetime + freshness_origin > now)
+//
+// And we call this quantity |freshness_lifetime + freshness_origin| the
+// freshness_expiry.
darin (slow to review) 2014/03/26 16:16:27 nit: this is no longer called "freshness_expiry".
gavinp 2016/04/29 15:04:51 That's right. Thanks for catching this.
+//
// Of course, there are other factors that can force a response to always be
// validated or re-fetched.
//
-bool HttpResponseHeaders::RequiresValidation(const Time& request_time,
- const Time& response_time,
- const Time& current_time) const {
- TimeDelta lifetime =
- GetFreshnessLifetime(response_time);
- if (lifetime == TimeDelta())
- return true;
+Time HttpResponseHeaders::GetExpirationTime(Time request_time,
+ Time response_time) const {
+ TimeDelta lifetime = GetFreshnessLifetime(response_time);
+ if (lifetime.is_max())
+ return Time::Max();
+
+ // From RFC 2616 section 13.2.3:
+ //
+ // Summary of age calculation algorithm, when a cache receives a response:
+ //
+ // /*
+ // * age_value
+ // * is the value of Age: header received by the cache with
+ // * this response.
+ // * date_value
+ // * is the value of the origin server's Date: header
+ // * request_time
+ // * is the (local) time when the cache made the request
+ // * that resulted in this cached response
+ // * response_time
+ // * is the (local) time when the cache received the
+ // * response
+ // * now
+ // * is the current (local) time
+ // */
+ // apparent_age = max(0, response_time - date_value);
+ // corrected_received_age = max(apparent_age, age_value);
+ // response_delay = response_time - request_time;
+ // corrected_initial_age = corrected_received_age + response_delay;
+ // resident_time = now - response_time;
+ // current_age = corrected_initial_age + resident_time;
darin (slow to review) 2014/03/26 16:16:27 it would help to add a comment below here (a "NOTE
gavinp 2016/04/29 15:04:51 Hmmm, except it doesn't, because this function lac
+ //
+
+ // If there is no Date header, then assume that the server response was
+ // generated at the time when we received the response.
+ Time date_value;
+ if (!GetDateValue(&date_value))
+ date_value = response_time;
+
+ // If there is no Age header, then assume age is zero. GetAgeValue does not
+ // modify its out param if the value does not exist.
+ TimeDelta age_value;
+ GetAgeValue(&age_value);
+
+ TimeDelta apparent_age = std::max(TimeDelta(), response_time - date_value);
+ TimeDelta corrected_received_age = std::max(apparent_age, age_value);
+ TimeDelta response_delay = response_time - request_time;
+ TimeDelta corrected_initial_age = corrected_received_age + response_delay;
- return lifetime <= GetCurrentAge(request_time, response_time, current_time);
+ // From the age calculation algorithm above, we can derive the corrected
+ // response time, the |now| for which |current_age = 0|. Substituting into the
+ // RFC 2616 13.2.3 equations and simplifying:
+ //
+ // 0 = corrected_initial_age + resident_time
+ //
+ // corrected_initial_age + corrected_response_time - response_time = 0
+ //
+ // corrected_response_time = response_time - corrected_initial_age
+
+ Time corrected_response_time = response_time - corrected_initial_age;
+ return corrected_response_time + lifetime;
}
// From RFC 2616 section 13.2.4:
@@ -939,8 +1001,7 @@ bool HttpResponseHeaders::RequiresValidation(const Time& request_time,
//
// freshness_lifetime = (date_value - last_modified_value) * 0.10
//
-TimeDelta HttpResponseHeaders::GetFreshnessLifetime(
- const Time& response_time) const {
+TimeDelta HttpResponseHeaders::GetFreshnessLifetime(Time response_time) const {
// Check for headers that force a response to never be fresh. For backwards
// compat, we treat "Pragma: no-cache" as a synonym for "Cache-Control:
// no-cache" even though RFC 2616 does not specify it.
@@ -1014,56 +1075,6 @@ TimeDelta HttpResponseHeaders::GetFreshnessLifetime(
return TimeDelta(); // not fresh
}
-// From RFC 2616 section 13.2.3:
-//
-// Summary of age calculation algorithm, when a cache receives a response:
-//
-// /*
-// * age_value
-// * is the value of Age: header received by the cache with
-// * this response.
-// * date_value
-// * is the value of the origin server's Date: header
-// * request_time
-// * is the (local) time when the cache made the request
-// * that resulted in this cached response
-// * response_time
-// * is the (local) time when the cache received the
-// * response
-// * now
-// * is the current (local) time
-// */
-// apparent_age = max(0, response_time - date_value);
-// corrected_received_age = max(apparent_age, age_value);
-// response_delay = response_time - request_time;
-// corrected_initial_age = corrected_received_age + response_delay;
-// resident_time = now - response_time;
-// current_age = corrected_initial_age + resident_time;
-//
-TimeDelta HttpResponseHeaders::GetCurrentAge(const Time& request_time,
- const Time& response_time,
- const Time& current_time) const {
- // If there is no Date header, then assume that the server response was
- // generated at the time when we received the response.
- Time date_value;
- if (!GetDateValue(&date_value))
- date_value = response_time;
-
- // If there is no Age header, then assume age is zero. GetAgeValue does not
- // modify its out param if the value does not exist.
- TimeDelta age_value;
- GetAgeValue(&age_value);
-
- TimeDelta apparent_age = std::max(TimeDelta(), response_time - date_value);
- TimeDelta corrected_received_age = std::max(apparent_age, age_value);
- TimeDelta response_delay = response_time - request_time;
- TimeDelta corrected_initial_age = corrected_received_age + response_delay;
- TimeDelta resident_time = current_time - response_time;
- TimeDelta current_age = corrected_initial_age + resident_time;
-
- return current_age;
-}
-
bool HttpResponseHeaders::GetMaxAgeValue(TimeDelta* result) const {
std::string name = "cache-control";
std::string value;
« no previous file with comments | « net/http/http_response_headers.h ('k') | net/http/http_response_headers_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698