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
This commit is contained in:
Dan Stillman 2009-01-15 21:40:15 +00:00
parent bd070f7b63
commit 0208806a95

View file

@ -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';
}