Add setRequestHeaders() method to Translate.Web

For use in zotero/translation-server#16 to pass Accept-Language through
to translation web requests
This commit is contained in:
Dan Stillman 2018-12-04 02:48:48 -07:00
parent a6fb0b35c3
commit 0706430609
2 changed files with 9 additions and 2 deletions

View file

@ -2053,6 +2053,13 @@ Zotero.Translate.Web.prototype.setCookieSandbox = function(cookieSandbox) {
this.cookieSandbox = cookieSandbox;
}
/**
* Sets headers to include in HTTP requests. Used by translation-server.
*/
Zotero.Translate.Web.prototype.setRequestHeaders = function (headers) {
this.requestHeaders = headers;
};
/**
* Sets the location to operate upon
*

View file

@ -360,7 +360,7 @@ Zotero.Utilities.Translate.prototype.doGet = function(urls, processor, done, res
} catch(e) {
translate.complete(false, e);
}
}, responseCharset, this._translate.cookieSandbox, requestHeaders);
}, responseCharset, this._translate.cookieSandbox, Object.assign({}, this._translate.requestHeaders, requestHeaders));
}
/**
@ -393,7 +393,7 @@ Zotero.Utilities.Translate.prototype.doPost = function(url, body, onDone, header
} catch(e) {
translate.complete(false, e);
}
}, headers, responseCharset, translate.cookieSandbox ? translate.cookieSandbox : undefined);
}, Object.assign({}, translate.requestHeaders, headers), responseCharset, translate.cookieSandbox ? translate.cookieSandbox : undefined);
}
Zotero.Utilities.Translate.prototype.urlToProxy = function(url) {