Update processDocuments() signature for allow passing headers
Also: - Actually use the cookie sandbox passed to processDocuments() For zotero/translation-server#16, we want to include Accept-Language (and maybe other headers) from the client request in upstream requests, which requires passing it to both non-translate processDocuments(). translation-server's non-translate processDocuments() is defined in that repo, but it's called by the cross-repo translate processDocuments() in utilities_translate.js, so the signature needs to be changed in both repos. We also apparently weren't using the cookieSandbox in client processDocuments() calls, though I think that only would've affected translator testing.
This commit is contained in:
parent
223f582aa7
commit
a6fb0b35c3
3 changed files with 21 additions and 5 deletions
|
@ -421,7 +421,9 @@ Zotero_TranslatorTester.prototype.fetchPageAndRunTest = function (test, testDone
|
||||||
testDoneCallback(obj, test, status, message);
|
testDoneCallback(obj, test, status, message);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
this._cookieSandbox,
|
{
|
||||||
|
cookieSandbox: this._cookieSandbox
|
||||||
|
}
|
||||||
)
|
)
|
||||||
.catch(function (e) {
|
.catch(function (e) {
|
||||||
testDoneCallback(this, test, "failed", "Translation failed to initialize: " + e);
|
testDoneCallback(this, test, "failed", "Translation failed to initialize: " + e);
|
||||||
|
|
|
@ -903,10 +903,12 @@ Zotero.HTTP = new function() {
|
||||||
* @param {String|String[]} urls URL(s) of documents to load
|
* @param {String|String[]} urls URL(s) of documents to load
|
||||||
* @param {Function} processor - Callback to be executed for each document loaded; if function returns
|
* @param {Function} processor - Callback to be executed for each document loaded; if function returns
|
||||||
* a promise, it's waited for before continuing
|
* a promise, it's waited for before continuing
|
||||||
* @param {Zotero.CookieSandbox} [cookieSandbox] Cookie sandbox object
|
* @param {Object} [options]
|
||||||
|
* @param {Zotero.CookieSandbox} [options.cookieSandbox] - Cookie sandbox object
|
||||||
|
* @param {Object} [options.headers] - Headers to include in the request
|
||||||
* @return {Promise<Array>} - A promise for an array of results from the processor runs
|
* @return {Promise<Array>} - A promise for an array of results from the processor runs
|
||||||
*/
|
*/
|
||||||
this.processDocuments = async function (urls, processor, cookieSandbox) {
|
this.processDocuments = async function (urls, processor, options = {}) {
|
||||||
// Handle old signature: urls, processor, onDone, onError, dontDelete, cookieSandbox
|
// Handle old signature: urls, processor, onDone, onError, dontDelete, cookieSandbox
|
||||||
if (arguments.length > 3) {
|
if (arguments.length > 3) {
|
||||||
Zotero.debug("Zotero.HTTP.processDocuments() now takes only 3 arguments -- update your code");
|
Zotero.debug("Zotero.HTTP.processDocuments() now takes only 3 arguments -- update your code");
|
||||||
|
@ -914,6 +916,14 @@ Zotero.HTTP = new function() {
|
||||||
var onError = arguments[3];
|
var onError = arguments[3];
|
||||||
var cookieSandbox = arguments[5];
|
var cookieSandbox = arguments[5];
|
||||||
}
|
}
|
||||||
|
else if (options instanceof Zotero.CookieSandbox) {
|
||||||
|
Zotero.debug("Zotero.HTTP.processDocuments() now takes an 'options' object for its third parameter -- update your code");
|
||||||
|
var cookieSandbox = options;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var cookieSandbox = options.cookieSandbox;
|
||||||
|
var headers = options.headers;
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof urls == "string") urls = [urls];
|
if (typeof urls == "string") urls = [urls];
|
||||||
var funcs = urls.map(url => () => {
|
var funcs = urls.map(url => () => {
|
||||||
|
@ -921,7 +931,9 @@ Zotero.HTTP = new function() {
|
||||||
"GET",
|
"GET",
|
||||||
url,
|
url,
|
||||||
{
|
{
|
||||||
responseType: 'document'
|
responseType: 'document',
|
||||||
|
cookieSandbox,
|
||||||
|
headers
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then((xhr) => {
|
.then((xhr) => {
|
||||||
|
|
|
@ -261,7 +261,9 @@ Zotero.Utilities.Translate.prototype.processDocuments = async function (urls, pr
|
||||||
if (!processor) return;
|
if (!processor) return;
|
||||||
return processDoc(doc);
|
return processDoc(doc);
|
||||||
},
|
},
|
||||||
translate.cookieSandbox
|
{
|
||||||
|
cookieSandbox: translate.cookieSandbox
|
||||||
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue