diff options
author | enal@chromium.org <enal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-17 18:56:07 +0000 |
---|---|---|
committer | enal@chromium.org <enal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-17 18:56:07 +0000 |
commit | d5aec989c84f6f5ba753976acc4e4aeda2525b82 (patch) | |
tree | c0cc77594adfbe06cb267d678b6c4471ec03f565 /net | |
parent | cf42e0685ede37f92a658553bddaf8eeeac99030 (diff) | |
download | chromium_src-d5aec989c84f6f5ba753976acc4e4aeda2525b82.zip chromium_src-d5aec989c84f6f5ba753976acc4e4aeda2525b82.tar.gz chromium_src-d5aec989c84f6f5ba753976acc4e4aeda2525b82.tar.bz2 |
Not allow compression when requesting multimedia
because ffmpeg does not expect compressed files.
(It does not make sense to compress audio/video anyways...)
http://codereview.chromium.org/7044092
BUG=47381
TEST=http://www.deafmac.org/html5/grinchsample.mp4 (Please clear browser cache, otherwise it can contain original GZIP-ed file requested by old browser)
Review URL: http://codereview.chromium.org/7044092
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89532 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/url_request/url_request_http_job.cc | 102 | ||||
-rw-r--r-- | net/url_request/url_request_unittest.cc | 33 |
2 files changed, 89 insertions, 46 deletions
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc index 4872792..c63aa0e 100644 --- a/net/url_request/url_request_http_job.cc +++ b/net/url_request/url_request_http_job.cc @@ -398,56 +398,66 @@ void URLRequestHttpJob::StartTransaction() { } void URLRequestHttpJob::AddExtraHeaders() { - // TODO(jar): Consider optimizing away SDCH advertising bytes when the URL is - // probably an img or such (and SDCH encoding is not likely). - bool advertise_sdch = SdchManager::Global() && - SdchManager::Global()->IsInSupportedDomain(request_->url()); - std::string avail_dictionaries; - if (advertise_sdch) { - SdchManager::Global()->GetAvailDictionaryList(request_->url(), - &avail_dictionaries); - - // The AllowLatencyExperiment() is only true if we've successfully done a - // full SDCH compression recently in this browser session for this host. - // Note that for this path, there might be no applicable dictionaries, and - // hence we can't participate in the experiment. - if (!avail_dictionaries.empty() && - SdchManager::Global()->AllowLatencyExperiment(request_->url())) { - // We are participating in the test (or control), and hence we'll - // eventually record statistics via either SDCH_EXPERIMENT_DECODE or - // SDCH_EXPERIMENT_HOLDBACK, and we'll need some packet timing data. - packet_timing_enabled_ = true; - if (base::RandDouble() < .01) { - sdch_test_control_ = true; // 1% probability. - advertise_sdch = false; - } else { - sdch_test_activated_ = true; + // Supply Accept-Encoding field only if it is not already provided. + // It should be provided IF the content is known to have restrictions on + // potential encoding, such as streaming multi-media. + // For details see bug 47381. + // TODO(jar, enal): jpeg files etc. should set up a request header if + // possible. Right now it is done only by buffered_resource_loader and + // simple_data_source. + if (!request_info_.extra_headers.HasHeader( + HttpRequestHeaders::kAcceptEncoding)) { + bool advertise_sdch = SdchManager::Global() && + SdchManager::Global()->IsInSupportedDomain(request_->url()); + std::string avail_dictionaries; + if (advertise_sdch) { + SdchManager::Global()->GetAvailDictionaryList(request_->url(), + &avail_dictionaries); + + // The AllowLatencyExperiment() is only true if we've successfully done a + // full SDCH compression recently in this browser session for this host. + // Note that for this path, there might be no applicable dictionaries, + // and hence we can't participate in the experiment. + if (!avail_dictionaries.empty() && + SdchManager::Global()->AllowLatencyExperiment(request_->url())) { + // We are participating in the test (or control), and hence we'll + // eventually record statistics via either SDCH_EXPERIMENT_DECODE or + // SDCH_EXPERIMENT_HOLDBACK, and we'll need some packet timing data. + packet_timing_enabled_ = true; + if (base::RandDouble() < .01) { + sdch_test_control_ = true; // 1% probability. + advertise_sdch = false; + } else { + sdch_test_activated_ = true; + } } } - } - // Supply Accept-Encoding headers first so that it is more likely that they - // will be in the first transmitted packet. This can sometimes make it easier - // to filter and analyze the streams to assure that a proxy has not damaged - // these headers. Some proxies deliberately corrupt Accept-Encoding headers. - if (!advertise_sdch) { - // Tell the server what compression formats we support (other than SDCH). - request_info_.extra_headers.SetHeader( - HttpRequestHeaders::kAcceptEncoding, "gzip,deflate"); - } else { - // Include SDCH in acceptable list. - request_info_.extra_headers.SetHeader( - HttpRequestHeaders::kAcceptEncoding, "gzip,deflate,sdch"); - if (!avail_dictionaries.empty()) { + // Supply Accept-Encoding headers first so that it is more likely that they + // will be in the first transmitted packet. This can sometimes make it + // easier to filter and analyze the streams to assure that a proxy has not + // damaged these headers. Some proxies deliberately corrupt Accept-Encoding + // headers. + if (!advertise_sdch) { + // Tell the server what compression formats we support (other than SDCH). request_info_.extra_headers.SetHeader( - kAvailDictionaryHeader, - avail_dictionaries); - sdch_dictionary_advertised_ = true; - // Since we're tagging this transaction as advertising a dictionary, we'll - // definitely employ an SDCH filter (or tentative sdch filter) when we get - // a response. When done, we'll record histograms via SDCH_DECODE or - // SDCH_PASSTHROUGH. Hence we need to record packet arrival times. - packet_timing_enabled_ = true; + HttpRequestHeaders::kAcceptEncoding, "gzip,deflate"); + } else { + // Include SDCH in acceptable list. + request_info_.extra_headers.SetHeader( + HttpRequestHeaders::kAcceptEncoding, "gzip,deflate,sdch"); + if (!avail_dictionaries.empty()) { + request_info_.extra_headers.SetHeader( + kAvailDictionaryHeader, + avail_dictionaries); + sdch_dictionary_advertised_ = true; + // Since we're tagging this transaction as advertising a dictionary, + // we'll definitely employ an SDCH filter (or tentative sdch filter) + // when we get a response. When done, we'll record histograms via + // SDCH_DECODE or SDCH_PASSTHROUGH. Hence we need to record packet + // arrival times. + packet_timing_enabled_ = true; + } } } diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc index 97ceb08..ffc1b41 100644 --- a/net/url_request/url_request_unittest.cc +++ b/net/url_request/url_request_unittest.cc @@ -2845,6 +2845,39 @@ TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { EXPECT_EQ(std::string("ru"), d.data_received()); } +// Check that default A-E header is sent. +TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) { + ASSERT_TRUE(test_server_.Start()); + + TestDelegate d; + TestURLRequest + req(test_server_.GetURL("echoheader?Accept-Encoding"), &d); + req.set_context(new TestURLRequestContext()); + HttpRequestHeaders headers; + req.SetExtraRequestHeaders(headers); + req.Start(); + MessageLoop::current()->Run(); + EXPECT_TRUE(ContainsString(d.data_received(), "gzip")); +} + +// Check that if request overrides the A-E header, the default is not appended. +// See http://crbug.com/47381 +TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) { + ASSERT_TRUE(test_server_.Start()); + + TestDelegate d; + TestURLRequest + req(test_server_.GetURL("echoheader?Accept-Encoding"), &d); + req.set_context(new TestURLRequestContext()); + HttpRequestHeaders headers; + headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity"); + req.SetExtraRequestHeaders(headers); + req.Start(); + MessageLoop::current()->Run(); + EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); + EXPECT_TRUE(ContainsString(d.data_received(), "identity")); +} + // Check that default A-C header is sent. TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { ASSERT_TRUE(test_server_.Start()); |