From 793618a51b1580b7d6625f450d67f2617c5ddd5e Mon Sep 17 00:00:00 2001 From: "rvargas@google.com" Date: Tue, 3 Nov 2009 23:08:12 +0000 Subject: Http cache: Make sure that we handle byte range requests that end up skipping the cache. BUG=26175 TEST=unittests Review URL: http://codereview.chromium.org/348053 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30877 0039d316-1c4b-4281-b951-d872f2087c98 --- net/http/http_cache.cc | 11 ++++++++--- net/http/http_cache_unittest.cc | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) (limited to 'net') diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index 0c3783d..b7158f0 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -462,10 +462,13 @@ int HttpCache::Transaction::Start(const HttpRequestInfo* request, if (!(mode_ & READ) && effective_load_flags_ & LOAD_ONLY_FROM_CACHE) return ERR_CACHE_MISS; - if (mode_ == NONE) + if (mode_ == NONE) { + if (partial_.get()) + partial_->RestoreHeaders(&custom_request_->extra_headers); rv = BeginNetworkRequest(); - else + } else { rv = AddToEntry(); + } // setting this here allows us to check for the existance of a callback_ to // determine if we are still inside Start. @@ -656,6 +659,8 @@ int HttpCache::Transaction::AddToEntry() { if (!entry) { DLOG(WARNING) << "unable to create cache entry"; mode_ = NONE; + if (partial_.get()) + partial_->RestoreHeaders(&custom_request_->extra_headers); return BeginNetworkRequest(); } } @@ -1586,7 +1591,7 @@ void HttpCache::Transaction::OnNetworkInfoAvailable(int result) { } if (result >= 0 || result == net::ERR_IO_PENDING) return; - } else if (partial_.get()) { + } else if (mode_ != NONE && partial_.get()) { // We are about to return the headers for a byte-range request to the // user, so let's fix them. partial_->FixResponseHeaders(response_.headers); diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc index 153fccd..8f09c544 100644 --- a/net/http/http_cache_unittest.cc +++ b/net/http/http_cache_unittest.cc @@ -2814,6 +2814,28 @@ TEST(HttpCache, RangeGET_NoDiskCache) { RemoveMockTransaction(&kRangeGET_TransactionOK); } +// Tests that we handle byte range requests that skip the cache. +TEST(HttpCache, RangeHEAD) { + MockHttpCache cache; + cache.http_cache()->set_enable_range_support(true); + AddMockTransaction(&kRangeGET_TransactionOK); + + MockTransaction transaction(kRangeGET_TransactionOK); + transaction.request_headers = "Range: bytes = -10\r\n" EXTRA_HEADER; + transaction.method = "HEAD"; + transaction.data = "rg: 70-79 "; + + std::string headers; + RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); + + EXPECT_TRUE(Verify206Response(headers, 70, 79)); + EXPECT_EQ(1, cache.network_layer()->transaction_count()); + EXPECT_EQ(0, cache.disk_cache()->open_count()); + EXPECT_EQ(0, cache.disk_cache()->create_count()); + + RemoveMockTransaction(&kRangeGET_TransactionOK); +} + #ifdef NDEBUG // This test hits a NOTREACHED so it is a release mode only test. TEST(HttpCache, RangeGET_OK_LoadOnlyFromCache) { -- cgit v1.1