Chromium Code Reviews| Index: net/http/http_response_headers.cc |
| diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc |
| index d0b2fc18ced38245b5b8397e33a3fe22f4cee804..af308a8ea14e121ab9978c78edc462a2b0f3e362 100644 |
| --- a/net/http/http_response_headers.cc |
| +++ b/net/http/http_response_headers.cc |
| @@ -917,28 +917,19 @@ bool HttpResponseHeaders::IsRedirectResponseCode(int response_code) { |
| // Of course, there are other factors that can force a response to always be |
| // validated or re-fetched. |
| // |
| -// 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 |
| -// |
| -ValidationType HttpResponseHeaders::RequiresValidation( |
| - const Time& request_time, |
| - const Time& response_time, |
| - const Time& current_time) const { |
| +bool HttpResponseHeaders::RequiresValidation(const Time& request_time, |
| + const Time& response_time, |
| + const Time& current_time) const { |
| FreshnessLifetimes lifetimes = GetFreshnessLifetimes(response_time); |
| - if (lifetimes.freshness.is_zero() && lifetimes.staleness.is_zero()) |
| - return VALIDATION_SYNCHRONOUS; |
| + if (lifetimes.freshness.is_zero()) |
| + return true; |
| TimeDelta age = GetCurrentAge(request_time, response_time, current_time); |
| if (lifetimes.freshness > age) |
| - return VALIDATION_NONE; |
| - |
| - if (lifetimes.freshness + lifetimes.staleness > age) |
| - return VALIDATION_ASYNCHRONOUS; |
| + return false; |
| - return VALIDATION_SYNCHRONOUS; |
| + return true; |
|
mmenke
2017/03/23 21:39:35
optional: Maybe just replace these last 4 lines w
scottmg
2017/03/24 22:46:00
Done. (I was a bit nervous about messing up on a b
|
| } |
| // From RFC 2616 section 13.2.4: |
| @@ -961,9 +952,6 @@ ValidationType HttpResponseHeaders::RequiresValidation( |
| // |
| // freshness_lifetime = (date_value - last_modified_value) * 0.10 |
| // |
| -// If the stale-while-revalidate directive is present, then it is used to set |
| -// the |staleness| time, unless it overridden by another directive. |
| -// |
| HttpResponseHeaders::FreshnessLifetimes |
| HttpResponseHeaders::GetFreshnessLifetimes(const Time& response_time) const { |
| FreshnessLifetimes lifetimes; |
| @@ -978,13 +966,8 @@ HttpResponseHeaders::GetFreshnessLifetimes(const Time& response_time) const { |
| return lifetimes; |
| } |
| - // Cache-Control directive must_revalidate overrides stale-while-revalidate. |
| bool must_revalidate = HasHeaderValue("cache-control", "must-revalidate"); |
|
mmenke
2017/03/23 21:39:35
Can get rid of the must_revalidate local, and inli
scottmg
2017/03/24 22:46:00
Done.
|
| - if (must_revalidate || !GetStaleWhileRevalidateValue(&lifetimes.staleness)) { |
| - DCHECK_EQ(TimeDelta(), lifetimes.staleness); |
| - } |
| - |
| // NOTE: "Cache-Control: max-age" overrides Expires, so we only check the |
| // Expires header after checking for max-age in GetFreshnessLifetimes. This |
| // is important since "Expires: <date in the past>" means not fresh, but |
| @@ -1051,13 +1034,11 @@ HttpResponseHeaders::GetFreshnessLifetimes(const Time& response_time) const { |
| if (response_code_ == 300 || response_code_ == 301 || response_code_ == 308 || |
| response_code_ == 410) { |
| lifetimes.freshness = TimeDelta::Max(); |
| - lifetimes.staleness = TimeDelta(); // It should never be stale. |
| return lifetimes; |
| } |
| // Our heuristic freshness estimate for this resource is 0 seconds, in |
| - // accordance with common browser behaviour. However, stale-while-revalidate |
| - // may still apply. |
| + // accordance with common browser behaviour. |
| DCHECK_EQ(TimeDelta(), lifetimes.freshness); |
| return lifetimes; |
| } |
| @@ -1168,11 +1149,6 @@ bool HttpResponseHeaders::GetExpiresValue(Time* result) const { |
| return GetTimeValuedHeader("Expires", result); |
| } |
| -bool HttpResponseHeaders::GetStaleWhileRevalidateValue( |
| - TimeDelta* result) const { |
| - return GetCacheControlDirective("stale-while-revalidate", result); |
| -} |
| - |
| bool HttpResponseHeaders::GetTimeValuedHeader(const std::string& name, |
| Time* result) const { |
| std::string value; |