diff options
author | Iain Merrick <husky@google.com> | 2011-01-07 05:51:41 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-01-07 05:51:41 -0800 |
commit | 9ac7ecaba0b11e8d497f140cbc566efafb88c4dc (patch) | |
tree | 814094359d9f764c4cf24bea0d08311b2d0b5dee /WebKit/android | |
parent | f5cff985b7f6ab5d60f57f56b5ce6abb46322f31 (diff) | |
parent | fb57cd2392293fed70fd4a7aebabb5b52ef5c41e (diff) | |
download | external_webkit-9ac7ecaba0b11e8d497f140cbc566efafb88c4dc.zip external_webkit-9ac7ecaba0b11e8d497f140cbc566efafb88c4dc.tar.gz external_webkit-9ac7ecaba0b11e8d497f140cbc566efafb88c4dc.tar.bz2 |
Merge "Fix MIME type handling for badly-behaved servers." into honeycomb
Diffstat (limited to 'WebKit/android')
-rw-r--r-- | WebKit/android/WebCoreSupport/WebResponse.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/WebKit/android/WebCoreSupport/WebResponse.cpp b/WebKit/android/WebCoreSupport/WebResponse.cpp index e564215..113fb05 100644 --- a/WebKit/android/WebCoreSupport/WebResponse.cpp +++ b/WebKit/android/WebCoreSupport/WebResponse.cpp @@ -115,18 +115,25 @@ void WebResponse::setUrl(const string& url) const string& WebResponse::getMimeType() { if (!m_mime.length() && m_url.length()) { - WTF::String wtfMime(m_url.c_str(), m_url.length()); - // Need to strip fragment and/or query if present. - size_t position = wtfMime.reverseFind('#'); - if (position != WTF::notFound) - wtfMime.truncate(position); - - position = wtfMime.reverseFind('?'); - if (position != WTF::notFound) - wtfMime.truncate(position); - - wtfMime = WebCore::MIMETypeRegistry::getMIMETypeForPath(wtfMime); - m_mime = std::string(wtfMime.utf8().data(), wtfMime.length()); + // Use "text/html" as a default (matching the behaviour of the Apache + // HTTP stack -- see guessMimeType() in LoadListener.java). + m_mime = "text/html"; + + // Try to guess a better MIME type from the URL. We call + // getMIMETypeForExtension rather than getMIMETypeForPath because the + // latter defaults to "application/octet-stream" on failure. + WebCore::KURL kurl(WebCore::ParsedURLString, m_url.c_str()); + WTF::String path = kurl.path(); + size_t extensionPos = path.reverseFind('.'); + if (extensionPos != WTF::notFound) { + // We found a file extension. + path.remove(0, extensionPos + 1); + WTF::String mime = WebCore::MIMETypeRegistry::getMIMETypeForExtension(path); + if (!mime.isEmpty()) { + // Great, we found a MIME type. + m_mime = std::string(mime.utf8().data(), mime.length()); + } + } } return m_mime; |