summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-03 23:08:12 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-03 23:08:12 +0000
commit793618a51b1580b7d6625f450d67f2617c5ddd5e (patch)
treed360875798e9d55a23d3d3f3beb981ae2cb22560 /net
parentca1abf5cbc6414dd636dd90a2c6c7dcfbdf1c802 (diff)
downloadchromium_src-793618a51b1580b7d6625f450d67f2617c5ddd5e.zip
chromium_src-793618a51b1580b7d6625f450d67f2617c5ddd5e.tar.gz
chromium_src-793618a51b1580b7d6625f450d67f2617c5ddd5e.tar.bz2
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
Diffstat (limited to 'net')
-rw-r--r--net/http/http_cache.cc11
-rw-r--r--net/http/http_cache_unittest.cc22
2 files changed, 30 insertions, 3 deletions
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) {