From a76510c0bdd1e3f96e79c4b91ed459fb2b4b29d2 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Mon, 12 Jan 2015 21:40:40 +0000 Subject: [PATCH] Set the CefResponse mime type before calling CefResourceHandler::GetResponseHeaders if it can be determined based on the requested path's file extension (issue #1098). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1970 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- libcef/browser/resource_request_job.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libcef/browser/resource_request_job.cc b/libcef/browser/resource_request_job.cc index 12d124a66..d35a1996e 100644 --- a/libcef/browser/resource_request_job.cc +++ b/libcef/browser/resource_request_job.cc @@ -17,6 +17,7 @@ #include "base/logging.h" #include "net/base/io_buffer.h" #include "net/base/load_flags.h" +#include "net/base/mime_util.h" #include "net/http/http_response_headers.h" #include "net/url_request/http_user_agent_settings.h" #include "net/url_request/url_request.h" @@ -356,6 +357,20 @@ void CefResourceRequestJob::SendHeaders() { response_ = new CefResponseImpl(); remaining_bytes_ = 0; + // Set the response mime type if it can be determined from the file extension. + if (request_->url().has_path()) { + const std::string& path = request_->url().path(); + size_t found = path.find_last_of("."); + if (found != std::string::npos) { + std::string suggest_mime_type; + if (net::GetWellKnownMimeTypeFromExtension( + base::FilePath::FromUTF8Unsafe(path.substr(found + 1)).value(), + &suggest_mime_type)) { + response_->SetMimeType(suggest_mime_type); + } + } + } + CefString redirectUrl; // Get header information from the handler.