Fix for b/2164520: Download manager should handle video/m4v MIME type.

The fix relaxes our processing of the content-disposition header by allowing unquoted filenames, and adds the m4v type to the MIME type map incase the content-disposition header was not specified.

Change-Id: Iaab0c5b17991a2c05eff5db01babe084444fd3b7
This commit is contained in:
Ben Murdoch
2009-10-13 10:46:15 +01:00
parent eab82c3c8c
commit 208360b22d
2 changed files with 7 additions and 2 deletions

View File

@@ -483,6 +483,7 @@ public class MimeTypeMap {
sMimeTypeMap.loadEntry("video/dv", "dif");
sMimeTypeMap.loadEntry("video/dv", "dv");
sMimeTypeMap.loadEntry("video/fli", "fli");
sMimeTypeMap.loadEntry("video/m4v", "m4v");
sMimeTypeMap.loadEntry("video/mpeg", "mpeg");
sMimeTypeMap.loadEntry("video/mpeg", "mpg");
sMimeTypeMap.loadEntry("video/mpeg", "mpe");

View File

@@ -367,19 +367,23 @@ public final class URLUtil {
/** Regex used to parse content-disposition headers */
private static final Pattern CONTENT_DISPOSITION_PATTERN =
Pattern.compile("attachment;\\s*filename\\s*=\\s*\"([^\"]*)\"");
Pattern.compile("attachment;\\s*filename\\s*=\\s*(\"?)([^\"]*)\\1\\s*$",
Pattern.CASE_INSENSITIVE);
/*
* Parse the Content-Disposition HTTP Header. The format of the header
* is defined here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html
* This header provides a filename for content that is going to be
* downloaded to the file system. We only support the attachment type.
* Note that RFC 2616 specifies the filename value must be double-quoted.
* Unfortunately some servers do not quote the value so to maintain
* consistent behaviour with other browsers, we allow unquoted values too.
*/
static String parseContentDisposition(String contentDisposition) {
try {
Matcher m = CONTENT_DISPOSITION_PATTERN.matcher(contentDisposition);
if (m.find()) {
return m.group(1);
return m.group(2);
}
} catch (IllegalStateException ex) {
// This function is defined as returning null when it can't parse the header