Index: net/http/http_response_headers.cc |
diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc |
index 3a9f7e04fe0c4bad6a232ae52270e55427532d03..8075b12dfd82c86f6714f5c50983dfbd5ea757e1 100644 |
--- a/net/http/http_response_headers.cc |
+++ b/net/http/http_response_headers.cc |
@@ -956,15 +956,29 @@ bool HttpResponseHeaders::IsRedirectResponseCode(int response_code) { |
// 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; |
- |
- return lifetime <= GetCurrentAge(request_time, response_time, current_time); |
+// From RFC 5861 section 3, a stale response may be used while revalidation is |
+// performed in the background if |
+// |
+// freshness_lifetime + stale_while_revalidate > current_age |
+// |
+HttpResponseHeaders::ValidationType HttpResponseHeaders::RequiresValidation( |
rvargas (doing something else)
2014/08/29 23:36:07
We don't need the class name on the return value,
Adam Rice
2014/09/01 14:43:00
Yes, we do.
|
+ const Time& request_time, |
+ const Time& response_time, |
+ const Time& current_time) const { |
+ TimeDelta lifetime; |
+ if (GetFreshnessLifetime(response_time, &lifetime) == NEVER_FRESH) |
+ return VALIDATION_SYNCHRONOUS; |
+ TimeDelta age = GetCurrentAge(request_time, response_time, current_time); |
+ |
+ if (lifetime > age) |
+ return VALIDATION_NONE; |
+ |
+ TimeDelta stale_while_revalidate; |
+ if (GetStaleWhileRevalidateValue(&stale_while_revalidate) && |
+ lifetime + stale_while_revalidate > age) |
+ return VALIDATION_ASYNCHRONOUS; |
+ |
+ return VALIDATION_SYNCHRONOUS; |
} |
// From RFC 2616 section 13.2.4: |
@@ -987,8 +1001,11 @@ bool HttpResponseHeaders::RequiresValidation(const Time& request_time, |
// |
// freshness_lifetime = (date_value - last_modified_value) * 0.10 |
// |
-TimeDelta HttpResponseHeaders::GetFreshnessLifetime( |
- const Time& response_time) const { |
+HttpResponseHeaders::FreshnessType HttpResponseHeaders::GetFreshnessLifetime( |
rvargas (doing something else)
2014/08/29 23:36:07
:(
Can we just say that in order to have async re
Adam Rice
2014/09/01 14:43:00
The problem is that max-age=0,stale-while-revalida
rvargas (doing something else)
2014/09/03 01:25:53
The ugly code (two, maybe contradictory outputs) i
Adam Rice
2014/09/05 15:17:11
If this is true, then it should apply also for max
rvargas (doing something else)
2014/09/05 22:52:39
I don't follow what you mean.
|
+ const Time& response_time, |
+ TimeDelta* lifetime) const { |
+ *lifetime = TimeDelta(); |
+ |
// 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. |
@@ -996,16 +1013,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 NEVER_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(lifetime)) |
+ return MAYBE_FRESH; |
// If there is no Date header, then assume that the server response was |
// generated at the time when we received the response. |
@@ -1016,10 +1032,12 @@ TimeDelta HttpResponseHeaders::GetFreshnessLifetime( |
Time expires_value; |
if (GetExpiresValue(&expires_value)) { |
// The expires value can be a date in the past! |
- if (expires_value > date_value) |
- return expires_value - date_value; |
+ if (expires_value > date_value) { |
+ *lifetime = expires_value - date_value; |
+ return MAYBE_FRESH; |
+ } |
- return TimeDelta(); // not fresh |
+ return NEVER_FRESH; |
} |
// From RFC 2616 section 13.4: |
@@ -1052,19 +1070,22 @@ TimeDelta HttpResponseHeaders::GetFreshnessLifetime( |
// TODO(darin): Implement a smarter heuristic. |
Time last_modified_value; |
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; |
+ // The last-modified value can be a date in the future! |
+ if (last_modified_value <= date_value) { |
+ *lifetime = (date_value - last_modified_value) / 10; |
+ return MAYBE_FRESH; |
+ } |
} |
} |
// These responses are implicitly fresh (unless otherwise overruled): |
if (response_code_ == 300 || response_code_ == 301 || response_code_ == 308 || |
response_code_ == 410) { |
- return TimeDelta::Max(); |
+ *lifetime = TimeDelta::Max(); |
+ return MAYBE_FRESH; |
} |
- return TimeDelta(); // not fresh |
+ return NEVER_FRESH; |
} |
// From RFC 2616 section 13.2.3: |