diff options
author | jar@google.com <jar@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-05 01:51:30 +0000 |
---|---|---|
committer | jar@google.com <jar@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-05 01:51:30 +0000 |
commit | 4c7073f666fd6c0209e1e9ae87e53698371ed973 (patch) | |
tree | 708984b8c463a1e4b08f40b64ed06db0b43b13d0 /net | |
parent | a98662d79f3890dfb3eaed7e01e12f46c3b7c4dc (diff) | |
download | chromium_src-4c7073f666fd6c0209e1e9ae87e53698371ed973.zip chromium_src-4c7073f666fd6c0209e1e9ae87e53698371ed973.tar.gz chromium_src-4c7073f666fd6c0209e1e9ae87e53698371ed973.tar.bz2 |
Correctly handle (and log) receipt of gzip response to SDCH encode proposal
When the only response to a SDCH encoding proposal (including a statement of
an Avail-Dict) is a gzip response, the filtering infrastructure needs to
add in a missing "sdch" sniffing filter. This filter should enter into
pass-through mode if the content does not have a valid SDCH header. This
functionality is critical to the latency experiment, which will signal
the fact that a session is in the control group by doing exactly the
above pattern (only using gzip, despite the dictionary).
This is a blocker for the Chrome SDCH latency experiment.
bug = 1520081
reviewers= huanr,openvcdiff,kmixter
Review URL: http://codereview.chromium.org/12964
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6415 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/filter.cc | 1 | ||||
-rw-r--r-- | net/base/gzip_filter_unittest.cc | 24 | ||||
-rw-r--r-- | net/base/sdch_filter.cc | 6 |
3 files changed, 29 insertions, 2 deletions
diff --git a/net/base/filter.cc b/net/base/filter.cc index 3069880..6bf48d1 100644 --- a/net/base/filter.cc +++ b/net/base/filter.cc @@ -89,7 +89,6 @@ void Filter::FixupEncodingTypes( // .gz files. We match Firefox's nsHttpChannel::ProcessNormal and ignore // the Content-Encoding here. encoding_types->clear(); - return; } if (!is_sdch_response) { diff --git a/net/base/gzip_filter_unittest.cc b/net/base/gzip_filter_unittest.cc index 7b2f73d..1fe4ee4 100644 --- a/net/base/gzip_filter_unittest.cc +++ b/net/base/gzip_filter_unittest.cc @@ -263,6 +263,30 @@ TEST_F(GZipUnitTest, DecodeGZip) { EXPECT_EQ(memcmp(source_buffer(), gzip_decode_buffer, source_len()), 0); } +// SDCH scenario: decoding gzip data when content type says sdch,gzip. +// This tests that sdch will degrade to pass through, and is what allows robust +// handling when the response *might* be sdch,gzip by simply adding in the +// tentative sdch decode. +// All test code is otherwise modeled after the "basic" scenario above. +TEST_F(GZipUnitTest, DecodeGZipWithMistakenSdch) { + // Decode the compressed data with filter + std::vector<Filter::FilterType> filter_types; + filter_types.push_back(Filter::FILTER_TYPE_SDCH); + filter_types.push_back(Filter::FILTER_TYPE_GZIP); + scoped_ptr<Filter> filter(Filter::Factory(filter_types, kDefaultBufferSize)); + ASSERT_TRUE(filter.get()); + memcpy(filter->stream_buffer(), gzip_encode_buffer_, gzip_encode_len_); + filter->FlushStreamBuffer(gzip_encode_len_); + + char gzip_decode_buffer[kDefaultBufferSize]; + int gzip_decode_size = kDefaultBufferSize; + filter->ReadData(gzip_decode_buffer, &gzip_decode_size); + + // Compare the decoding result with source data + EXPECT_TRUE(gzip_decode_size == source_len()); + EXPECT_EQ(memcmp(source_buffer(), gzip_decode_buffer, source_len()), 0); +} + // Tests we can call filter repeatedly to get all the data decoded. // To do that, we create a filter with a small buffer that can not hold all // the input data. diff --git a/net/base/sdch_filter.cc b/net/base/sdch_filter.cc index ae4d5ac..4b9cf70 100644 --- a/net/base/sdch_filter.cc +++ b/net/base/sdch_filter.cc @@ -144,7 +144,11 @@ Filter::FilterStatus SdchFilter::ReadFilteredData(char* dest_buffer, return FILTER_NEED_MORE_DATA; } if (PASS_THROUGH == decoding_status_) { - return CopyOut(dest_buffer, dest_len); + // We must pass in available_space, but it will be changed to bytes_used. + FilterStatus result = CopyOut(dest_buffer, &available_space); + // Accumulate the returned count of bytes_used (a.k.a., available_space). + *dest_len += available_space; + return result; } DCHECK(false); decoding_status_ = DECODING_ERROR; |