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
This commit is contained in:
Abe Jellinek 2023-05-25 17:57:32 +03:00
parent 76b7fd0dc1
commit a4c3f5267b

View file

@ -162,8 +162,10 @@ Zotero.MIMETypeHandler = new function () {
channel.QueryInterface(Components.interfaces.nsITraceableChannel);
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);