diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-04 18:59:29 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-04 18:59:29 +0000 |
commit | 207d58c747ad0009fa3a918f67c33fc0dafe74f1 (patch) | |
tree | 3fcb45b4c0203799006a31c530ad5de4632819cf /net | |
parent | 27152f2f1c394eec9727e0aba5217239e7b2d4e5 (diff) | |
download | chromium_src-207d58c747ad0009fa3a918f67c33fc0dafe74f1.zip chromium_src-207d58c747ad0009fa3a918f67c33fc0dafe74f1.tar.gz chromium_src-207d58c747ad0009fa3a918f67c33fc0dafe74f1.tar.bz2 |
Update the response time of http cache entries on 304.
BUG=http://crbug.com/20594
TEST=HttpCacheTest.UpdatesResponseTimeOn304
Review URL: http://codereview.chromium.org/197024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25484 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/http/http_cache.cc | 2 | ||||
-rw-r--r-- | net/http/http_cache_unittest.cc | 91 | ||||
-rw-r--r-- | net/http/http_transaction_unittest.cc | 5 | ||||
-rw-r--r-- | net/http/http_transaction_unittest.h | 6 |
4 files changed, 98 insertions, 6 deletions
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index 727a059..44b5d00 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -1443,6 +1443,8 @@ void HttpCache::Transaction::OnNetworkInfoAvailable(int result) { // TODO(wtc): should we update cached certificate // (response_.ssl_info), too? response_.headers->Update(*new_response->headers); + response_.response_time = new_response->response_time; + if (response_.headers->HasHeaderValue("cache-control", "no-store")) { cache_->DoomEntry(cache_key_); } else { diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc index e62783f..fa20f13 100644 --- a/net/http/http_cache_unittest.cc +++ b/net/http/http_cache_unittest.cc @@ -9,6 +9,7 @@ #include "base/string_util.h" #include "net/base/net_errors.h" #include "net/base/load_flags.h" +#include "net/base/ssl_cert_request_info.h" #include "net/disk_cache/disk_cache.h" #include "net/http/http_byte_range.h" #include "net/http/http_request_info.h" @@ -386,7 +387,7 @@ void ReadAndVerifyTransaction(net::HttpTransaction* trans, void RunTransactionTestWithRequest(net::HttpCache* cache, const MockTransaction& trans_info, const MockHttpRequest& request, - std::string* response_headers) { + net::HttpResponseInfo* response_info) { TestCompletionCallback callback; // write to the cache @@ -402,23 +403,31 @@ void RunTransactionTestWithRequest(net::HttpCache* cache, const net::HttpResponseInfo* response = trans->GetResponseInfo(); ASSERT_TRUE(response); - if (response_headers) - response->headers->GetNormalizedHeaders(response_headers); + if (response_info) + *response_info = *response; ReadAndVerifyTransaction(trans.get(), trans_info); } void RunTransactionTest(net::HttpCache* cache, const MockTransaction& trans_info) { - return RunTransactionTestWithRequest( + RunTransactionTestWithRequest( cache, trans_info, MockHttpRequest(trans_info), NULL); } +void RunTransactionTestWithResponseInfo(net::HttpCache* cache, + const MockTransaction& trans_info, + net::HttpResponseInfo* response) { + RunTransactionTestWithRequest( + cache, trans_info, MockHttpRequest(trans_info), response); +} + void RunTransactionTestWithResponse(net::HttpCache* cache, const MockTransaction& trans_info, std::string* response_headers) { - return RunTransactionTestWithRequest( - cache, trans_info, MockHttpRequest(trans_info), response_headers); + net::HttpResponseInfo response; + RunTransactionTestWithResponseInfo(cache, trans_info, &response); + response.headers->GetNormalizedHeaders(response_headers); } // This class provides a handler for kFastNoStoreGET_Transaction so that the @@ -453,6 +462,7 @@ const MockTransaction kFastNoStoreGET_Transaction = { net::LOAD_VALIDATE_CACHE, "HTTP/1.1 200 OK", "Cache-Control: max-age=10000\n", + base::Time(), "<html><body>Google Blah Blah</body></html>", TEST_MODE_SYNC_NET_START, &FastTransactionServer::FastNoStoreHandler, @@ -559,6 +569,7 @@ const MockTransaction kRangeGET_TransactionOK = { "ETag: \"foo\"\n" "Accept-Ranges: bytes\n" "Content-Length: 10\n", + base::Time(), "rg: 40-49 ", TEST_MODE_NORMAL, &RangeTransactionServer::RangeHandler, @@ -2484,3 +2495,71 @@ TEST(HttpCache, CacheDisabledMode) { EXPECT_EQ(0, cache.disk_cache()->open_count()); EXPECT_EQ(1, cache.disk_cache()->create_count()); } + +// Other tests check that the response headers of the cached response +// get updated on 304. Here we specifically check that the +// HttpResponseHeaders::response_time field also gets updated. +// http://crbug.com/20594. +TEST(HttpCache, UpdatesResponseTimeOn304) { + MockHttpCache cache; + + const char* kUrl = "http://foobar"; + const char* kData = "body"; + + MockTransaction mock_network_response = { 0 }; + mock_network_response.url = kUrl; + + AddMockTransaction(&mock_network_response); + + // Request |kUrl|, causing |kNetResponse1| to be written to the cache. + + MockTransaction request = { 0 }; + request.url = kUrl; + request.method = "GET"; + request.request_headers = ""; + request.data = kData; + + static const Response kNetResponse1 = { + "HTTP/1.1 200 OK", + "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" + "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", + kData + }; + + kNetResponse1.AssignTo(&mock_network_response); + + RunTransactionTest(cache.http_cache(), request); + + // Request |kUrl| again, this time validating the cache and getting + // a 304 back. + + request.load_flags = net::LOAD_VALIDATE_CACHE; + + static const Response kNetResponse2 = { + "HTTP/1.1 304 Not Modified", + "Date: Wed, 22 Jul 2009 03:15:26 GMT\n", + "" + }; + + kNetResponse2.AssignTo(&mock_network_response); + + base::Time t = base::Time() + base::TimeDelta::FromHours(1234); + mock_network_response.response_time = t; + + net::HttpResponseInfo response; + RunTransactionTestWithResponseInfo(cache.http_cache(), request, &response); + + // The response time should have been updated. + EXPECT_EQ(t.ToInternalValue(), + response.response_time.ToInternalValue()); + + std::string headers; + response.headers->GetNormalizedHeaders(&headers); + + EXPECT_EQ("HTTP/1.1 200 OK\n" + "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" + "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", + headers); + + RemoveMockTransaction(&mock_network_response); +} diff --git a/net/http/http_transaction_unittest.cc b/net/http/http_transaction_unittest.cc index e22c398..4a0cef7 100644 --- a/net/http/http_transaction_unittest.cc +++ b/net/http/http_transaction_unittest.cc @@ -26,6 +26,7 @@ const MockTransaction kSimpleGET_Transaction = { net::LOAD_NORMAL, "HTTP/1.1 200 OK", "Cache-Control: max-age=10000\n", + base::Time(), "<html><body>Google Blah Blah</body></html>", TEST_MODE_NORMAL, NULL, @@ -39,6 +40,7 @@ const MockTransaction kSimplePOST_Transaction = { net::LOAD_NORMAL, "HTTP/1.1 200 OK", "", + base::Time(), "<html><body>Google Blah Blah</body></html>", TEST_MODE_NORMAL, NULL, @@ -53,6 +55,7 @@ const MockTransaction kTypicalGET_Transaction = { "HTTP/1.1 200 OK", "Date: Wed, 28 Nov 2007 09:40:09 GMT\n" "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n", + base::Time(), "<html><body>Google Blah Blah</body></html>", TEST_MODE_NORMAL, NULL, @@ -67,6 +70,7 @@ const MockTransaction kETagGET_Transaction = { "HTTP/1.1 200 OK", "Cache-Control: max-age=10000\n" "Etag: foopy\n", + base::Time(), "<html><body>Google Blah Blah</body></html>", TEST_MODE_NORMAL, NULL, @@ -80,6 +84,7 @@ const MockTransaction kRangeGET_Transaction = { net::LOAD_NORMAL, "HTTP/1.1 200 OK", "Cache-Control: max-age=10000\n", + base::Time(), "<html><body>Google Blah Blah</body></html>", TEST_MODE_NORMAL, NULL, diff --git a/net/http/http_transaction_unittest.h b/net/http/http_transaction_unittest.h index aef6693..1f4919f 100644 --- a/net/http/http_transaction_unittest.h +++ b/net/http/http_transaction_unittest.h @@ -47,6 +47,8 @@ struct MockTransaction { int load_flags; const char* status; const char* response_headers; + // If |response_time| is unspecified, the current time will be used. + base::Time response_time; const char* data; int test_mode; MockTransactionHandler handler; @@ -218,7 +220,11 @@ class MockNetworkTransaction : public net::HttpTransaction { response_.request_time = base::Time::Now(); response_.was_cached = false; + response_.response_time = base::Time::Now(); + if (!t->response_time.is_null()) + response_.response_time = t->response_time; + response_.headers = new net::HttpResponseHeaders(header_data); response_.ssl_info.cert_status = t->cert_status; data_ = resp_data; |