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

Unified Diff: net/http/http_cache_transaction.cc

Issue 391763002: Initial implementation of Chrome-Freshness header. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove const from directive_size. Created 6 years, 5 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 | « no previous file | net/http/http_cache_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_cache_transaction.cc
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc
index aba792330bf4dcf92e78deeb88ff44ff88fc663f..58cb3b417eb10b497c7c53bfe0a42749bf01ba3d 100644
--- a/net/http/http_cache_transaction.cc
+++ b/net/http/http_cache_transaction.cc
@@ -15,13 +15,16 @@
#include "base/bind.h"
#include "base/compiler_specific.h"
+#include "base/format_macros.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
#include "base/metrics/sparse_histogram.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "net/base/completion_callback.h"
#include "net/base/io_buffer.h"
@@ -48,6 +51,9 @@ using base::TimeTicks;
namespace {
+// TODO(ricea): Move this to HttpResponseHeaders once it is standardised.
+static const char kFreshnessHeader[] = "Chromium-Resource-Freshness";
+
// Stores data relevant to the statistics of writing and reading entire
// certificate chains using DiskBasedCertCache. |num_pending_ops| is the number
// of certificates in the chain that have pending operations in the
@@ -2257,6 +2263,28 @@ bool HttpCache::Transaction::ConditionalizeRequest() {
bool use_if_range = partial_.get() && !partial_->IsCurrentRangeCached() &&
!invalid_range_;
+ if (!use_if_range) {
+ // stale-while-revalidate is not useful when we only have a partial response
+ // cached, so don't set the header in that case.
+ TimeDelta stale_while_revalidate;
+ if (response_.headers->GetStaleWhileRevalidateValue(
+ &stale_while_revalidate) &&
+ stale_while_revalidate > TimeDelta()) {
+ TimeDelta max_age =
+ response_.headers->GetFreshnessLifetime(response_.response_time);
+ TimeDelta current_age = response_.headers->GetCurrentAge(
+ response_.request_time, response_.response_time, Time::Now());
+
+ custom_request_->extra_headers.SetHeader(
+ kFreshnessHeader,
+ base::StringPrintf("max-age=%" PRId64
+ ",stale-while-revalidate=%" PRId64 ",age=%" PRId64,
+ max_age.InSeconds(),
+ stale_while_revalidate.InSeconds(),
+ current_age.InSeconds()));
+ }
+ }
+
if (!etag_value.empty()) {
if (use_if_range) {
// We don't want to switch to WRITE mode if we don't have this block of a
« no previous file with comments | « no previous file | net/http/http_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698