summaryrefslogtreecommitdiffstats
path: root/net/http
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-28 18:46:35 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-28 18:46:35 +0000
commit86291440d4c7db5fbf5cb6c4a270777b540ce736 (patch)
tree0fc4f924ce00cd263e42bdd7c2eb622ce5893467 /net/http
parent16184b7ada3760e4d2eb832fa9ef97ad734a125e (diff)
downloadchromium_src-86291440d4c7db5fbf5cb6c4a270777b540ce736.zip
chromium_src-86291440d4c7db5fbf5cb6c4a270777b540ce736.tar.gz
chromium_src-86291440d4c7db5fbf5cb6c4a270777b540ce736.tar.bz2
Http cache: Bypass the cache for range requests that have validation headers.
BUG=20017 TEST=unittests Review URL: http://codereview.chromium.org/177016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24759 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r--net/http/http_cache.cc8
-rw-r--r--net/http/http_cache_unittest.cc34
2 files changed, 41 insertions, 1 deletions
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc
index 73e1ffa..b0cc6d9 100644
--- a/net/http/http_cache.cc
+++ b/net/http/http_cache.cc
@@ -81,6 +81,7 @@ struct HeaderNameAndValue {
static const HeaderNameAndValue kPassThroughHeaders[] = {
{ "if-unmodified-since", NULL }, // causes unexpected 412s
{ "if-match", NULL }, // causes unexpected 412s
+ { "if-range", NULL },
{ NULL, NULL }
};
@@ -804,6 +805,12 @@ void HttpCache::Transaction::SetRequest(LoadLog* load_log,
}
}
+ // We don't support ranges and validation headers.
+ if (range_found && num_validation_headers) {
+ LOG(WARNING) << "Byte ranges AND validation headers found.";
+ effective_load_flags_ |= LOAD_DISABLE_CACHE;
+ }
+
if (range_found && !(effective_load_flags_ & LOAD_DISABLE_CACHE)) {
partial_.reset(new PartialData);
if (partial_->Init(request_->extra_headers, new_extra_headers)) {
@@ -814,6 +821,7 @@ void HttpCache::Transaction::SetRequest(LoadLog* load_log,
custom_request_->extra_headers = new_extra_headers;
} else {
// The range is invalid or we cannot handle it properly.
+ LOG(WARNING) << "Invalid byte range found.";
effective_load_flags_ |= LOAD_DISABLE_CACHE;
partial_.reset(NULL);
}
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index 90b0774..e62783f 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -1639,7 +1639,6 @@ TEST(HttpCache, SimplePOST_LoadOnlyFromCache_Hit) {
TEST(HttpCache, RangeGET_SkipsCache) {
MockHttpCache cache;
- cache.http_cache()->set_enable_range_support(true);
// Test that we skip the cache for range GET requests. Eventually, we will
// want to cache these, but we'll still have cases where skipping the cache
@@ -1668,6 +1667,39 @@ TEST(HttpCache, RangeGET_SkipsCache) {
EXPECT_EQ(0, cache.disk_cache()->create_count());
}
+// Test that we skip the cache for range requests that include a validation
+// header.
+TEST(HttpCache, RangeGET_SkipsCache2) {
+ MockHttpCache cache;
+ cache.http_cache()->set_enable_range_support(true);
+
+ MockTransaction transaction(kRangeGET_Transaction);
+ transaction.request_headers = "If-None-Match: foo\n"
+ "Range: bytes = 40-49\n";
+ RunTransactionTest(cache.http_cache(), transaction);
+
+ EXPECT_EQ(1, cache.network_layer()->transaction_count());
+ EXPECT_EQ(0, cache.disk_cache()->open_count());
+ EXPECT_EQ(0, cache.disk_cache()->create_count());
+
+ transaction.request_headers =
+ "If-Modified-Since: Wed, 28 Nov 2007 00:45:20 GMT\n"
+ "Range: bytes = 40-49\n";
+ RunTransactionTest(cache.http_cache(), transaction);
+
+ EXPECT_EQ(2, cache.network_layer()->transaction_count());
+ EXPECT_EQ(0, cache.disk_cache()->open_count());
+ EXPECT_EQ(0, cache.disk_cache()->create_count());
+
+ transaction.request_headers = "If-Range: bla\n"
+ "Range: bytes = 40-49\n";
+ RunTransactionTest(cache.http_cache(), transaction);
+
+ EXPECT_EQ(3, cache.network_layer()->transaction_count());
+ EXPECT_EQ(0, cache.disk_cache()->open_count());
+ EXPECT_EQ(0, cache.disk_cache()->create_count());
+}
+
// Tests that receiving 206 for a regular request is handled correctly.
TEST(HttpCache, GET_Crazy206) {
MockHttpCache cache;