From 8f3f3c9b8646cd6708ac3f18803d60c5ca7e9209 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Thu, 25 May 2023 17:57:32 +0300 Subject: [PATCH] Fix ScienceDirect PDF downloads ScienceDirect sometimes puts the `name` directive at the end of the Content-Type header instead of in Content-Disposition. That isn't strictly spec-approved, but there are other directives (`charset` and `boundary`) that can also be appended to Content-Type per the spec. We want to strip them before looking for handlers. https://forums.zotero.org/discussion/105194/sciencedirect-pdf-downloads-not-working-zotero-7 (cherry picked from commit a4c3f5267b873df578ef7608a23d1816dc883cc5) --- chrome/content/zotero/xpcom/mimeTypeHandler.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/mimeTypeHandler.js b/chrome/content/zotero/xpcom/mimeTypeHandler.js index fd1eca8c7f..61146a96d6 100644 --- a/chrome/content/zotero/xpcom/mimeTypeHandler.js +++ b/chrome/content/zotero/xpcom/mimeTypeHandler.js @@ -142,8 +142,10 @@ Zotero.MIMETypeHandler = new function () { if(channel.loadFlags & Components.interfaces.nsIHttpChannel.LOAD_DOCUMENT_URI) { channel.QueryInterface(Components.interfaces.nsIHttpChannel); try { + // Get the main directive of the Content-Type header + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type#syntax + var contentType = channel.getResponseHeader("Content-Type").split(';')[0].toLowerCase(); // remove content-disposition headers for EndNote, etc. - var contentType = channel.getResponseHeader("Content-Type").toLowerCase(); for (let handledType of _ignoreContentDispositionTypes) { if (contentType.startsWith(handledType)) { channel.setResponseHeader("Content-Disposition", "inline", false);