Index: net/http/http_response_headers.cc |
diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc |
index 88017d0b93ecfb286c2a2503c3a94ef814a56bfb..93cf2236ae7d215735eafc573e2bfa2a77453b1f 100644 |
--- a/net/http/http_response_headers.cc |
+++ b/net/http/http_response_headers.cc |
@@ -905,20 +905,37 @@ bool HttpResponseHeaders::IsRedirectResponseCode(int response_code) { |
// |
// response_is_fresh = (freshness_lifetime > current_age) |
// |
+// Into this equation, we substitute |current_age = now - freshness_origin|, |
+// 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. |
+// |
// 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::GetFreshnessExpiry(Time request_time, |
+ Time response_time) const { |
+ TimeDelta lifetime; |
+ bool finite_lifetime; |
+ GetFreshnessLifetime(response_time, &lifetime, &finite_lifetime); |
+ if (!finite_lifetime) |
+ return Time::Max(); |
+ Time origin = GetFreshnessOrigin(request_time, response_time); |
+ return origin + lifetime; |
+} |
- return lifetime <= GetCurrentAge(request_time, response_time, current_time); |
+bool HttpResponseHeaders::RequiresValidation(base::Time request_time, |
+ base::Time response_time, |
+ base::Time current_time) const { |
+ return GetFreshnessExpiry(request_time, response_time) <= current_time; |
} |
+ |
// From RFC 2616 section 13.2.4: |
// |
// The max-age directive takes priority over Expires, so if max-age is present |
@@ -939,8 +956,13 @@ bool HttpResponseHeaders::RequiresValidation(const Time& request_time, |
// |
// freshness_lifetime = (date_value - last_modified_value) * 0.10 |
// |
-TimeDelta HttpResponseHeaders::GetFreshnessLifetime( |
- const Time& response_time) const { |
+void HttpResponseHeaders::GetFreshnessLifetime( |
+ Time response_time, |
+ TimeDelta* finite_freshness_lifetime, |
+ bool* was_finite) const { |
+ *finite_freshness_lifetime = TimeDelta(); |
+ *was_finite = true; |
+ |
// 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. |
@@ -948,16 +970,15 @@ TimeDelta HttpResponseHeaders::GetFreshnessLifetime( |
HasHeaderValue("cache-control", "no-store") || |
HasHeaderValue("pragma", "no-cache") || |
HasHeaderValue("vary", "*")) // see RFC 2616 section 13.6 |
- return TimeDelta(); // not fresh |
+ return; // not fresh |
// NOTE: "Cache-Control: max-age" overrides Expires, so we only check the |
// Expires header after checking for max-age in GetFreshnessLifetime. This |
// is important since "Expires: <date in the past>" means not fresh, but |
// it should not trump a max-age value. |
- TimeDelta max_age_value; |
- if (GetMaxAgeValue(&max_age_value)) |
- return max_age_value; |
+ if (GetMaxAgeValue(finite_freshness_lifetime)) |
+ return; |
// If there is no Date header, then assume that the server response was |
// generated at the time when we received the response. |
@@ -969,9 +990,8 @@ TimeDelta HttpResponseHeaders::GetFreshnessLifetime( |
if (GetExpiresValue(&expires_value)) { |
// The expires value can be a date in the past! |
if (expires_value > date_value) |
- return expires_value - date_value; |
- |
- return TimeDelta(); // not fresh |
+ *finite_freshness_lifetime = expires_value - date_value; |
+ return; |
} |
// From RFC 2616 section 13.4: |
@@ -1003,15 +1023,18 @@ TimeDelta HttpResponseHeaders::GetFreshnessLifetime( |
if (GetLastModifiedValue(&last_modified_value)) { |
// The last-modified value can be a date in the past! |
if (last_modified_value <= date_value) |
- return (date_value - last_modified_value) / 10; |
+ *finite_freshness_lifetime = (date_value - last_modified_value) / 10; |
+ return; |
} |
} |
// These responses are implicitly fresh (unless otherwise overruled): |
- if (response_code_ == 300 || response_code_ == 301 || response_code_ == 410) |
- return TimeDelta::FromMicroseconds(kint64max); |
gavinp
2014/02/13 17:37:59
This line is an abstraction violation that skates
|
+ if (response_code_ == 300 || response_code_ == 301 || response_code_ == 410) { |
+ *was_finite = false; |
+ return; |
+ } |
- return TimeDelta(); // not fresh |
+ return; // not fresh. |
} |
// From RFC 2616 section 13.2.3: |
@@ -1040,9 +1063,15 @@ TimeDelta HttpResponseHeaders::GetFreshnessLifetime( |
// 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 { |
+// From this, we can derive the freshness origin, the time at which the |
+// current_age = 0 and solve for now (aka freshness_origin): |
+// |
+// corrected_initial_age + resident_time = 0 |
+// corrected_initial_age + freshness_origin - response_time = 0 |
+// freshness_origin = response_time - corrected_initial_age |
+// |
+Time HttpResponseHeaders::GetFreshnessOrigin(Time request_time, |
+ Time response_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; |
@@ -1058,10 +1087,8 @@ TimeDelta HttpResponseHeaders::GetCurrentAge(const Time& request_time, |
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; |
+ return response_time - corrected_initial_age; |
} |
bool HttpResponseHeaders::GetMaxAgeValue(TimeDelta* result) const { |