From 8fc9d50400e62e028b1c389745535ad78c351bb2 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 25 Dec 2006 08:18:40 +0000 Subject: [PATCH] Fixes #460, importFromURL fails when importing PDFs from servers that do not properly support HEAD requests Override MIME type to application/pdf if extension is .pdf -- not all that robust, but it should work for most sites --- chrome/content/zotero/xpcom/attachments.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index ef783fbd6..06da05cd7 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -178,6 +178,13 @@ Zotero.Attachments = new function(){ 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) + if (ext == 'pdf') { + mimeType = 'application/pdf'; + } + // If we can load this natively, use a hidden browser (so we can // get the charset and title and index the document) if (Zotero.MIME.hasNativeHandler(mimeType, ext)){ @@ -294,8 +301,18 @@ Zotero.Attachments = new function(){ // Otherwise do a head request for the mime type Zotero.Utilities.HTTP.doHead(url, function(obj){ + var mimeType = obj.channel.contentType; + + // 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) + var ext = _getExtensionFromURL(url); + if (ext == 'pdf') { + mimeType = 'application/pdf'; + } + _addToDB(null, url, title, Zotero.Attachments.LINK_MODE_LINKED_URL, - obj.channel.contentType, null, sourceItemID); + mimeType, null, sourceItemID); }); return true;