From 0208806a9557dbad4f3b72e4ef4fafa5f001867d Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 15 Jan 2009 21:40:15 +0000 Subject: [PATCH] Better fix for invalid HEAD responses -- Wiley was returning 405 on HEAD even for GETs that succeeded, so we're not just leaving the MIME type blank if the HEAD response is rejected Also made the 'pdf' match check a bit more flexible -- now can be the end of the last segment or the query string and not just the extension --- chrome/content/zotero/xpcom/attachments.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index c8b6361929..d4f6e60663 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -195,22 +195,22 @@ Zotero.Attachments = new function(){ if (obj.status != 200 && obj.status != 204) { Zotero.debug("Attachment HEAD request returned with status code " + obj.status + " in Attachments.importFromURL()", 2); - return false; + var mimeType = ''; + } + else { + var mimeType = obj.channel.contentType; } - - var mimeType = obj.channel.contentType; var nsIURL = Components.classes["@mozilla.org/network/standard-url;1"] .createInstance(Components.interfaces.nsIURL); nsIURL.spec = url; - var ext = nsIURL.fileExtension; // Override MIME type to application/pdf if extension is .pdf -- // workaround for sites that respond to the HEAD request with an // invalid MIME type (https://www.zotero.org/trac/ticket/460) // // Downloaded file is inspected below and deleted if actually HTML - if (ext == 'pdf') { + if (nsIURL.fileName.match(/pdf$/) || url.match(/pdf$/)) { mimeType = 'application/pdf'; }