Update MIME.getMIMETypeFromURL() for non-Bluebird HTTP.request()

This commit is contained in:
Dan Stillman 2019-05-25 07:34:41 -04:00
parent e8dd1f7824
commit 7aa68a0f75
2 changed files with 37 additions and 30 deletions

View file

@ -509,7 +509,8 @@ Zotero.Attachments = new function(){
return process(contentType, Zotero.MIME.hasNativeHandler(contentType));
}
return Zotero.MIME.getMIMETypeFromURL(url, cookieSandbox).spread(process);
var args = yield Zotero.MIME.getMIMETypeFromURL(url, cookieSandbox);
return process(...args);
});

View file

@ -327,9 +327,16 @@ Zotero.MIME = new function(){
* @param {Zotero.CookieSandbox} [cookieSandbox]
* @return {Promise}
*/
this.getMIMETypeFromURL = function (url, cookieSandbox) {
return Zotero.HTTP.promise("HEAD", url, { cookieSandbox: cookieSandbox, successCodes: false })
.then(function (xmlhttp) {
this.getMIMETypeFromURL = async function (url, cookieSandbox) {
var xmlhttp = await Zotero.HTTP.request(
"HEAD",
url,
{
cookieSandbox,
successCodes: false
}
);
if (xmlhttp.status != 200 && xmlhttp.status != 204) {
Zotero.debug("Attachment HEAD request returned with status code "
+ xmlhttp.status + " in Zotero.MIME.getMIMETypeFromURL()", 2);
@ -356,7 +363,6 @@ Zotero.MIME = new function(){
var hasNativeHandler = Zotero.MIME.hasNativeHandler(mimeType, ext);
return [mimeType, hasNativeHandler];
});
}