| 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..49fd2521e46df40ccb94f2c683999d7a05ffca1e 100644
|
| --- a/net/http/http_response_headers.cc
|
| +++ b/net/http/http_response_headers.cc
|
| @@ -905,18 +905,28 @@ 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;
|
| -
|
| - return lifetime <= GetCurrentAge(request_time, response_time, current_time);
|
| +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;
|
| }
|
|
|
| // From RFC 2616 section 13.2.4:
|
| @@ -939,8 +949,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 +963,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 +983,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 +1016,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);
|
| + 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 +1056,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 +1080,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 {
|
|
|