diff options
author | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-16 23:33:57 +0000 |
---|---|---|
committer | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-16 23:33:57 +0000 |
commit | e19d7133ce2bcb816fbd6e707622cc43a5735c1d (patch) | |
tree | cf72ba0113d3063583225bc6819b3112a3f2e4f0 /chrome | |
parent | 4772c9574cdd4ef513b5fb5994212a6187bc0b12 (diff) | |
download | chromium_src-e19d7133ce2bcb816fbd6e707622cc43a5735c1d.zip chromium_src-e19d7133ce2bcb816fbd6e707622cc43a5735c1d.tar.gz chromium_src-e19d7133ce2bcb816fbd6e707622cc43a5735c1d.tar.bz2 |
Sniff 204 responses as text/plain to avoid creating unwanted downloads.
BUG=24391
TEST=ResourceDispatcherHostTest.MimeSniff204
Review URL: http://codereview.chromium.org/274075
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29355 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/renderer_host/buffered_resource_handler.cc | 15 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc | 27 |
2 files changed, 34 insertions, 8 deletions
diff --git a/chrome/browser/renderer_host/buffered_resource_handler.cc b/chrome/browser/renderer_host/buffered_resource_handler.cc index ad31e8d..347bf69 100644 --- a/chrome/browser/renderer_host/buffered_resource_handler.cc +++ b/chrome/browser/renderer_host/buffered_resource_handler.cc @@ -154,12 +154,11 @@ bool BufferedResourceHandler::DelayResponse() { const bool sniffing_blocked = LowerCaseEqualsASCII(content_type_options, "nosniff"); - const bool no_data = - response_->response_head.headers && // Can be NULL if FTP. - (response_->response_head.headers->response_code() == 304 || - response_->response_head.headers->response_code() == 204); - const bool we_would_like_to_sniff = - no_data ? false : net::ShouldSniffMimeType(request_->url(), mime_type); + const bool not_modified_status = + response_->response_head.headers && + response_->response_head.headers->response_code() == 304; + const bool we_would_like_to_sniff = not_modified_status ? + false : net::ShouldSniffMimeType(request_->url(), mime_type); RecordSnifferMetrics(sniffing_blocked, we_would_like_to_sniff, mime_type); @@ -172,7 +171,7 @@ bool BufferedResourceHandler::DelayResponse() { return true; } - if (sniffing_blocked && mime_type.empty() && !no_data) { + if (sniffing_blocked && mime_type.empty() && !not_modified_status) { // Ugg. The server told us not to sniff the content but didn't give us a // mime type. What's a browser to do? Turns out, we're supposed to treat // the response as "text/plain". This is the most secure option. @@ -202,7 +201,7 @@ bool BufferedResourceHandler::DelayResponse() { return true; } - if (!no_data && ShouldWaitForPlugins()) { + if (!not_modified_status && ShouldWaitForPlugins()) { wait_for_plugins_ = true; return true; } diff --git a/chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc b/chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc index 78994a7..6c08025 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc @@ -846,3 +846,30 @@ TEST_F(ResourceDispatcherHostTest, MimeNotSniffed2) { GetResponseHead(msgs[0], &response_head); ASSERT_EQ("", response_head.mime_type); } + +TEST_F(ResourceDispatcherHostTest, MimeSniff204) { + EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(0)); + + std::string response("HTTP/1.1 204 No Content\n\n"); + std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), + response.size())); + std::string response_data; + SetResponse(raw_headers, response_data); + + HandleScheme("http"); + MakeTestRequest(0, 1, GURL("http:bla")); + + // Flush all pending requests. + while (URLRequestTestJob::ProcessOnePendingMessage()); + + EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(0)); + + // Sorts out all the messages we saw by request. + ResourceIPCAccumulator::ClassifiedMessages msgs; + accum_.GetClassifiedMessages(&msgs); + ASSERT_EQ(1U, msgs.size()); + + ResourceResponseHead response_head; + GetResponseHead(msgs[0], &response_head); + ASSERT_EQ("text/plain", response_head.mime_type); +} |