Allow ZU.doGet to have requestHeaders (#1062)
This is mainly for translators which have to work with content negotiation, e.g. ORCID API or API calls of ISBN agencies.
This commit is contained in:
parent
ed9e655871
commit
3dfb73faba
2 changed files with 13 additions and 4 deletions
|
@ -201,11 +201,12 @@ Zotero.HTTP = new function() {
|
||||||
* @param {Function} onDone Callback to be executed upon request completion
|
* @param {Function} onDone Callback to be executed upon request completion
|
||||||
* @param {String} responseCharset Character set to force on the response
|
* @param {String} responseCharset Character set to force on the response
|
||||||
* @param {Zotero.CookieSandbox} [cookieSandbox] Cookie sandbox object
|
* @param {Zotero.CookieSandbox} [cookieSandbox] Cookie sandbox object
|
||||||
|
* @param {Object} requestHeaders HTTP headers to include with request
|
||||||
* @return {XMLHttpRequest} The XMLHttpRequest object if the request was sent, or
|
* @return {XMLHttpRequest} The XMLHttpRequest object if the request was sent, or
|
||||||
* false if the browser is offline
|
* false if the browser is offline
|
||||||
* @deprecated Use {@link Zotero.HTTP.promise}
|
* @deprecated Use {@link Zotero.HTTP.promise}
|
||||||
*/
|
*/
|
||||||
this.doGet = function(url, onDone, responseCharset, cookieSandbox) {
|
this.doGet = function(url, onDone, responseCharset, cookieSandbox, requestHeaders) {
|
||||||
if (url instanceof Components.interfaces.nsIURI) {
|
if (url instanceof Components.interfaces.nsIURI) {
|
||||||
// Don't display password in console
|
// Don't display password in console
|
||||||
var disp = this.getDisplayURI(url);
|
var disp = this.getDisplayURI(url);
|
||||||
|
@ -236,6 +237,13 @@ Zotero.HTTP = new function() {
|
||||||
channel.contentCharset = responseCharset;
|
channel.contentCharset = responseCharset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set request headers
|
||||||
|
if (requestHeaders) {
|
||||||
|
for (var header in requestHeaders) {
|
||||||
|
xmlhttp.setRequestHeader(header, requestHeaders[header]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Don't cache GET requests
|
// Don't cache GET requests
|
||||||
xmlhttp.channel.loadFlags |= Components.interfaces.nsIRequest.LOAD_BYPASS_CACHE;
|
xmlhttp.channel.loadFlags |= Components.interfaces.nsIRequest.LOAD_BYPASS_CACHE;
|
||||||
|
|
||||||
|
|
|
@ -298,9 +298,10 @@ Zotero.Utilities.Translate.prototype.processDocuments = function(urls, processor
|
||||||
* @param {Function} processor Callback to be executed for each document loaded
|
* @param {Function} processor Callback to be executed for each document loaded
|
||||||
* @param {Function} done Callback to be executed after all documents have been loaded
|
* @param {Function} done Callback to be executed after all documents have been loaded
|
||||||
* @param {String} responseCharset Character set to force on the response
|
* @param {String} responseCharset Character set to force on the response
|
||||||
|
* @param {Object} requestHeaders HTTP headers to include with request
|
||||||
* @return {Boolean} True if the request was sent, or false if the browser is offline
|
* @return {Boolean} True if the request was sent, or false if the browser is offline
|
||||||
*/
|
*/
|
||||||
Zotero.Utilities.Translate.prototype.doGet = function(urls, processor, done, responseCharset) {
|
Zotero.Utilities.Translate.prototype.doGet = function(urls, processor, done, responseCharset, requestHeaders) {
|
||||||
var callAgain = false,
|
var callAgain = false,
|
||||||
me = this,
|
me = this,
|
||||||
translate = this._translate;
|
translate = this._translate;
|
||||||
|
@ -332,7 +333,7 @@ Zotero.Utilities.Translate.prototype.doGet = function(urls, processor, done, res
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
translate.complete(false, e);
|
translate.complete(false, e);
|
||||||
}
|
}
|
||||||
}, responseCharset, this._translate.cookieSandbox);
|
}, responseCharset, this._translate.cookieSandbox, requestHeaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue