Commit 1720d2a6 authored by Shivani Sharma's avatar Shivani Sharma Committed by Commit Bot

[Http Cache] Do not preserve incomplete compressed responses.

If a response is not complete and has a content-encoding header, it
should not be marked as truncated since we do not want it to lead to
range requests for future requests.

TEST=net_unittests --gtest_filter=
WritersTest.ContentEncodingShouldNotTruncate

Also manually verified that the test case reported in the bug is fixed.

Bug: 820862
Change-Id: Ie3f4098e769e257632058af2215054809ca8c89f
Reviewed-on: https://chromium-review.googlesource.com/962346
Commit-Queue: Shivani Sharma <shivanisha@chromium.org>
Reviewed-by: default avatarMaks Orlovich <morlovich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543481}
parent f14f94de
......@@ -283,6 +283,11 @@ bool HttpCache::Writers::ShouldTruncate() {
return false;
}
if (response_info_truncation_.headers->HasHeader("Content-Encoding")) {
should_keep_entry_ = false;
return false;
}
int64_t content_length =
response_info_truncation_.headers->GetContentLength();
if (content_length >= 0 && content_length <= current_size)
......
......@@ -106,7 +106,8 @@ class WritersTest : public testing::Test {
void CreateWritersAddTransaction(
HttpCache::ParallelWritingPattern parallel_writing_pattern_ =
HttpCache::PARALLEL_WRITING_JOIN) {
HttpCache::PARALLEL_WRITING_JOIN,
bool content_encoding_present = false) {
TestCompletionCallback callback;
// Create and Start a mock network transaction.
......@@ -116,6 +117,8 @@ class WritersTest : public testing::Test {
NetLogWithSource());
base::RunLoop().RunUntilIdle();
response_info_ = *(network_transaction->GetResponseInfo());
if (content_encoding_present)
response_info_.headers->AddHeader("Content-Encoding: gzip");
// Create a mock cache transaction.
std::unique_ptr<TestHttpCacheTransaction> transaction =
......@@ -188,6 +191,28 @@ class WritersTest : public testing::Test {
return OK;
}
int ReadFewBytes(std::string* result) {
EXPECT_TRUE(transactions_.size() >= (size_t)1);
TestHttpCacheTransaction* transaction = transactions_.begin()->get();
TestCompletionCallback callback;
std::string content;
int rv = 0;
scoped_refptr<IOBuffer> buf(new IOBuffer(5));
rv = writers_->Read(buf.get(), 5, callback.callback(), transaction);
if (rv == ERR_IO_PENDING) {
rv = callback.WaitForResult();
base::RunLoop().RunUntilIdle();
}
if (rv > 0)
result->append(buf->data(), rv);
else if (rv < 0)
return rv;
return OK;
}
void ReadVerifyTwoDifferentBufferLengths(
const std::vector<int>& buffer_lengths) {
EXPECT_EQ(2u, buffer_lengths.size());
......@@ -782,4 +807,17 @@ TEST_F(WritersTest, StopCachingWithNotKeepEntry) {
EXPECT_FALSE(ShouldKeepEntry());
}
// Tests that if content-encoding is set, the entry should not be marked as
// truncated, since we should not be creating range requests for compressed
// entries.
TEST_F(WritersTest, ContentEncodingShouldNotTruncate) {
CreateWritersAddTransaction(HttpCache::PARALLEL_WRITING_JOIN,
true /* content_encoding_present */);
std::string result;
ReadFewBytes(&result);
EXPECT_FALSE(ShouldTruncate());
EXPECT_FALSE(ShouldKeepEntry());
}
} // namespace net
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment