summaryrefslogtreecommitdiffstats
path: root/net/http
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-09 19:18:41 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-09 19:18:41 +0000
commitb7d05ab3d0cce2d74d24f702641b3f5702584dab (patch)
tree30511d93a0898c99dd4e4200a78acca34d67a45c /net/http
parent7de99596feecaa24900a082a721ef8d4f57b47ee (diff)
downloadchromium_src-b7d05ab3d0cce2d74d24f702641b3f5702584dab.zip
chromium_src-b7d05ab3d0cce2d74d24f702641b3f5702584dab.tar.gz
chromium_src-b7d05ab3d0cce2d74d24f702641b3f5702584dab.tar.bz2
If a server answers a cache validation request with 304 and cache-control:no-store,
we return the cached entry to the requestor but doom the entry so it's not used in the future. B=b/1363355 R=darin TEST=unit test. Review URL: http://codereview.chromium.org/13273 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6605 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r--net/http/http_cache.cc6
-rw-r--r--net/http/http_cache_unittest.cc44
2 files changed, 49 insertions, 1 deletions
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc
index 3271035..b82795c 100644
--- a/net/http/http_cache.cc
+++ b/net/http/http_cache.cc
@@ -853,7 +853,11 @@ void HttpCache::Transaction::OnNetworkInfoAvailable(int result) {
if (new_response->headers->response_code() == 304) {
// Update cached response based on headers in new_response
response_.headers->Update(*new_response->headers);
- WriteResponseInfoToEntry();
+ if (response_.headers->HasHeaderValue("cache-control", "no-store")) {
+ cache_->DoomEntry(cache_key_);
+ } else {
+ WriteResponseInfoToEntry();
+ }
if (entry_) {
cache_->ConvertWriterToReader(entry_);
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index 92ac6ca..ab4e26b 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -668,6 +668,50 @@ TEST(HttpCache, ETagGET_ConditionalRequest_304) {
EXPECT_EQ(1, cache.disk_cache()->create_count());
}
+static void ETagGet_ConditionalRequest_NoStore_Handler(
+ const net::HttpRequestInfo* request,
+ std::string* response_status,
+ std::string* response_headers,
+ std::string* response_data) {
+ EXPECT_TRUE(request->extra_headers.find("If-None-Match") !=
+ std::string::npos);
+ response_status->assign("HTTP/1.1 304 Not Modified");
+ response_headers->assign("Cache-Control: no-store\n");
+ response_data->clear();
+}
+
+TEST(HttpCache, ETagGET_ConditionalRequest_304_NoStore) {
+ MockHttpCache cache;
+
+ ScopedMockTransaction transaction(kETagGET_Transaction);
+
+ // Write to the cache.
+ RunTransactionTest(cache.http_cache(), transaction);
+
+ EXPECT_EQ(1, cache.network_layer()->transaction_count());
+ EXPECT_EQ(0, cache.disk_cache()->open_count());
+ EXPECT_EQ(1, cache.disk_cache()->create_count());
+
+ // Get the same URL again, but this time we expect it to result
+ // in a conditional request.
+ transaction.load_flags = net::LOAD_VALIDATE_CACHE;
+ transaction.handler = ETagGet_ConditionalRequest_NoStore_Handler;
+ RunTransactionTest(cache.http_cache(), transaction);
+
+ EXPECT_EQ(2, cache.network_layer()->transaction_count());
+ EXPECT_EQ(1, cache.disk_cache()->open_count());
+ EXPECT_EQ(1, cache.disk_cache()->create_count());
+
+ ScopedMockTransaction transaction2(kETagGET_Transaction);
+
+ // Write to the cache again. This should create a new entry.
+ RunTransactionTest(cache.http_cache(), transaction2);
+
+ EXPECT_EQ(3, cache.network_layer()->transaction_count());
+ EXPECT_EQ(1, cache.disk_cache()->open_count());
+ EXPECT_EQ(2, cache.disk_cache()->create_count());
+}
+
TEST(HttpCache, SimplePOST_SkipsCache) {
MockHttpCache cache;