diff options
author | John Reck <jreck@google.com> | 2010-11-19 15:01:47 -0800 |
---|---|---|
committer | John Reck <jreck@google.com> | 2010-11-22 08:59:46 -0800 |
commit | 787e29b54f206839549283289018384538f050f0 (patch) | |
tree | 1ced13b49b0714d7aa28c269db3b23211c5e9f1b /WebKit/android/WebCoreSupport/WebResponse.cpp | |
parent | 4ed81ac4810cd587cc2afc3b7f292c1281eca93a (diff) | |
download | external_webkit-787e29b54f206839549283289018384538f050f0.zip external_webkit-787e29b54f206839549283289018384538f050f0.tar.gz external_webkit-787e29b54f206839549283289018384538f050f0.tar.bz2 |
Fixes the handling of unspecified mime-type
Bug: 3211038 and 3211569
If the server doesn't specify a Content-Type header in the response,
there was no mime-type set when using the Chrome HTTP stack. This change
fixes it so that it makes a guess based off of the URL extension.
Change-Id: I33ef90c1db54bdccb4e143795656f4f9b56572ca
Diffstat (limited to 'WebKit/android/WebCoreSupport/WebResponse.cpp')
-rw-r--r-- | WebKit/android/WebCoreSupport/WebResponse.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/WebKit/android/WebCoreSupport/WebResponse.cpp b/WebKit/android/WebCoreSupport/WebResponse.cpp index 57e9460..8f68a6a 100644 --- a/WebKit/android/WebCoreSupport/WebResponse.cpp +++ b/WebKit/android/WebCoreSupport/WebResponse.cpp @@ -26,9 +26,13 @@ #include "config.h" #include "WebResponse.h" +#include "MIMETypeRegistry.h" +#include "PlatformString.h" #include "ResourceResponse.h" #include "ResourceError.h" +#include <wtf/text/CString.h> + using namespace std; namespace android { @@ -42,6 +46,8 @@ WebResponse::WebResponse(URLRequest* request) m_url = request->url().spec(); m_host = request->url().HostNoBrackets(); request->GetMimeType(&m_mime); + setMimeType(m_mime); + request->GetCharset(&m_encoding); m_expectedSize = request->GetExpectedContentSize(); @@ -67,6 +73,7 @@ WebResponse::WebResponse(const string &url, const string &mimeType, long long ex , m_mime(mimeType) , m_url(url) { + setMimeType(mimeType); } WebCore::ResourceResponse WebResponse::createResourceResponse() @@ -110,6 +117,17 @@ const string& WebResponse::getMimeType() const return m_mime; } +void WebResponse::setMimeType(const std::string &mimeType) +{ + if (mimeType.length() == 0 && m_url.length() > 0) { + WTF::String wtfMime(m_url.c_str(), m_url.length()); + wtfMime = WebCore::MIMETypeRegistry::getMIMETypeForPath(wtfMime); + m_mime = std::string(wtfMime.utf8().data(), wtfMime.length()); + } else { + m_mime = mimeType; + } +} + bool WebResponse::getHeader(const string& header, string* result) const { map<string, string>::const_iterator iter = m_headerFields.find(header); |