diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-05 01:15:45 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-05 01:15:45 +0000 |
commit | d9adff2c5cc1c9b57e7acfb8259eeec19a7b951b (patch) | |
tree | 56a3c979de4f7f7c9cd8a4eb94714c2aa3d62261 /net/http | |
parent | 841f7a103cbd7be1cf95c4d147854355fd5bca99 (diff) | |
download | chromium_src-d9adff2c5cc1c9b57e7acfb8259eeec19a7b951b.zip chromium_src-d9adff2c5cc1c9b57e7acfb8259eeec19a7b951b.tar.gz chromium_src-d9adff2c5cc1c9b57e7acfb8259eeec19a7b951b.tar.bz2 |
Bug fixing for range request support in HttpCache
TEST=net_unittests --gtest_filter=HttpCache.GET_Previous206_NotModified
Step to reproduce the failure:
1. Sparse cache has data for (0 - 9)
2. Make a non-range request for the resource
3. Server replies with 304 not modified
4. User would get 304 modified while 200 is expected
The cause is that PartialData::ResponseHeadersOK requires a full specified
range to accept the response when server replies with 304. This is not a
valid assumption as the response of 304 can be caused by the cache submitting
a range request for validation purpose.
Review URL: http://codereview.chromium.org/198018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25569 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r-- | net/http/http_cache.cc | 1 | ||||
-rw-r--r-- | net/http/http_cache_unittest.cc | 35 | ||||
-rw-r--r-- | net/http/partial_data.cc | 2 |
3 files changed, 36 insertions, 2 deletions
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index be9dc48..855c7e8 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -945,7 +945,6 @@ int HttpCache::Transaction::BeginPartialCacheValidation() { if (!custom_request_.get()) { custom_request_.reset(new HttpRequestInfo(*request_)); request_ = custom_request_.get(); - DCHECK(custom_request_->extra_headers.empty()); } } diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc index a72c36d..674d8fd 100644 --- a/net/http/http_cache_unittest.cc +++ b/net/http/http_cache_unittest.cc @@ -1995,6 +1995,41 @@ TEST(HttpCache, GET_Previous206) { RemoveMockTransaction(&kRangeGET_TransactionOK); } +// Tests that we can handle non-range requests when we have cached the first +// part of the object and server replies with 304 (Not Modified). +TEST(HttpCache, GET_Previous206_NotModified) { + MockHttpCache cache; + cache.http_cache()->set_enable_range_support(true); + + MockTransaction transaction(kRangeGET_TransactionOK); + transaction.request_headers = "Range: bytes = 0-9\r\n"; + transaction.data = "rg: 00-09 "; + AddMockTransaction(&transaction); + std::string headers; + + // Write to the cache (0-9). + RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); + + EXPECT_TRUE(Verify206Response(headers, 0, 9)); + EXPECT_EQ(1, cache.network_layer()->transaction_count()); + EXPECT_EQ(0, cache.disk_cache()->open_count()); + EXPECT_EQ(1, cache.disk_cache()->create_count()); + + // Read from the cache (0-9), write and read from cache (10 - 79), + MockTransaction transaction2(kRangeGET_TransactionOK); + transaction2.request_headers = "Foo: bar\r\n"; + transaction2.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " + "rg: 50-59 rg: 60-69 rg: 70-79 "; + RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); + + EXPECT_EQ(0U, headers.find("HTTP/1.1 200 OK\n")); + EXPECT_EQ(3, cache.network_layer()->transaction_count()); + EXPECT_EQ(1, cache.disk_cache()->open_count()); + EXPECT_EQ(1, cache.disk_cache()->create_count()); + + RemoveMockTransaction(&transaction); +} + // Tests that we can handle cached 206 responses that are not sparse. TEST(HttpCache, GET_Previous206_NotSparse) { MockHttpCache cache; diff --git a/net/http/partial_data.cc b/net/http/partial_data.cc index fcd7808..1b4b575 100644 --- a/net/http/partial_data.cc +++ b/net/http/partial_data.cc @@ -179,7 +179,7 @@ bool PartialData::IsRequestedRangeOK() { bool PartialData::ResponseHeadersOK(const HttpResponseHeaders* headers) { if (headers->response_code() == 304) { - if (truncated_) + if (!byte_range_.IsValid() || truncated_) return true; // We must have a complete range here. |