Skip to content

Commit

Permalink
Do not show dialog when content and type are missing
Browse files Browse the repository at this point in the history
The site from #14 appears to respond without Content-Type header,
and `Content-Length: 0`.
  • Loading branch information
Rob--W committed Nov 15, 2017
1 parent 59c620e commit 1e276f7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ chrome.webRequest.onHeadersReceived.addListener(async function(details) {
var contentDisposition = getHeader(details.responseHeaders, 'content-disposition');
var isSniffingTextPlain = ContentHandlers.isSniffableTextPlain(originalCT.contentType,
getHeader(details.responseHeaders, 'content-encoding'));
var contentLength = getHeader(details.responseHeaders, 'content-length');
if (contentLength !== undefined) contentLength = parseInt(contentLength);
contentLength = contentLength >= 0 ? contentLength : -1;
var {mimeType} = originalCT;

if (!contentDisposition || !r_contentDispositionAttachment.test(contentDisposition)) {
Expand Down Expand Up @@ -50,6 +53,11 @@ chrome.webRequest.onHeadersReceived.addListener(async function(details) {
// Uncertain whether MIME-type triggers download. Exit now, to be on the safe side.
return;
}
if (contentLength <= 0 && !mimeType) {
// No specified content type, so defaulting to content sniffing.
// There is however no content to sniff, so do not show a dialog.
return;
}
}

// Determine file name
Expand All @@ -61,10 +69,6 @@ chrome.webRequest.onHeadersReceived.addListener(async function(details) {
filename = getFilenameFromURL(details.url);
}

var contentLength = getHeader(details.responseHeaders, 'content-length');
if (contentLength !== undefined) contentLength = parseInt(contentLength);
contentLength = contentLength >= 0 ? contentLength : -1;

var guessedMimeType = mime_fromFilename(filename) || mimeType;
var isSniffingMimeType =
mimeType === 'application/octet-stream' && Prefs.get('octet-sniff-mime');
Expand Down

0 comments on commit 1e276f7

Please sign in to comment.