Deduct file type from content-disposition

A user encountered a response that looks like:

URL: some gibberish
Headers:

    Content-Type: application/octet-stream
    Content-Disposition: attachment; filename="something.pdf"

In the Chrome extension, the "attachment" content disposition is almost
always ignored (i.e. the PDF Viewer will try to view it anyway). So we
need to fall back to the Content-Disposition header if the URL check is
inconclusive.
This commit is contained in:
Rob Wu 2016-09-17 22:21:24 -07:00
parent f062695d62
commit ae74e1bbd6

View File

@ -73,9 +73,19 @@ function isPdfFile(details) {
var header = getHeaderFromHeaders(details.responseHeaders, 'content-type');
if (header) {
var headerValue = header.value.toLowerCase().split(';',1)[0].trim();
return (headerValue === 'application/pdf' ||
headerValue === 'application/octet-stream' &&
details.url.toLowerCase().indexOf('.pdf') > 0);
if (headerValue === 'application/pdf') {
return true;
}
if (headerValue === 'application/octet-stream') {
if (details.url.toLowerCase().indexOf('.pdf') > 0) {
return true;
}
var cdHeader =
getHeaderFromHeaders(details.responseHeaders, 'content-disposition');
if (cdHeader && /\.pdf(["']|$)/i.test(cdHeader.value)) {
return true;
}
}
}
}