Improves proxy support (#1129)

Improves proxy support

- Automatically detect and dehyphenise https proxies which use EZProxy
  HttpsHyphens
- Web translators now pass around Zotero.Proxy instances which can
  proxify/deproxify urls passed to `translate.setLocation()` before calling
  `translate.getTranslators()`/ translate.detect()`. The proxy passing is
  done within connector background/injected processes and between
  standalone and connectors.
- Proxy protocol unified with connectors. Connectors can now pass
  proxies to `/connector/save_items`. The proxies will be used to resolve
  true item and attachment urls when saving.

Closes zotero/zotero#578, zotero/zotero#721

Relevant zotero/zotero#34, zotero/zotero#556
This commit is contained in:
Adomas Ven 2016-12-12 14:29:59 +02:00 committed by GitHub
parent c2ebcc9dbc
commit 747c11c917
16 changed files with 392 additions and 124 deletions

View file

@ -680,6 +680,49 @@ describe("Zotero.Translate", function() {
assert.isNumber(translation.newItems[0].id);
assert.ok(collection.hasItem(translation.newItems[0].id));
});
});
describe('#saveItems', function() {
it("should deproxify item and attachment urls when proxy provided", function* (){
var itemID;
var item = loadSampleData('journalArticle');
item = item.journalArticle;
item.url = 'https://www-example-com.proxy.example.com/';
item.attachments = [{
url: 'https://www-example-com.proxy.example.com/pdf.pdf',
mimeType: 'application/pdf',
title: 'Example PDF'}];
var itemSaver = new Zotero.Translate.ItemSaver({
libraryID: Zotero.Libraries.userLibraryID,
attachmentMode: Zotero.Translate.ItemSaver.ATTACHMENT_MODE_FILE,
proxy: new Zotero.Proxy({scheme: 'https://%h.proxy.example.com/%p', dotsToHyphens: true})
});
var itemDeferred = Zotero.Promise.defer();
var attachmentDeferred = Zotero.Promise.defer();
itemSaver.saveItems([item], Zotero.Promise.coroutine(function* (attachment, progressPercentage) {
// ItemSaver returns immediately without waiting for attachments, so we use the callback
// to test attachments
if (progressPercentage != 100) return;
try {
yield itemDeferred.promise;
let item = Zotero.Items.get(itemID);
attachment = Zotero.Items.get(item.getAttachments()[0]);
assert.equal(attachment.getField('url'), 'https://www.example.com/pdf.pdf');
attachmentDeferred.resolve();
} catch (e) {
attachmentDeferred.reject(e);
}
})).then(function(items) {
try {
assert.equal(items[0].getField('url'), 'https://www.example.com/');
itemID = items[0].id;
itemDeferred.resolve();
} catch (e) {
itemDeferred.reject(e);
}
});
yield Zotero.Promise.all([itemDeferred.promise, attachmentDeferred.promise]);
});
});
});
});