Gzip-compress API uploads larger than 1000 characters

This commit is contained in:
Dan Stillman 2016-03-28 02:35:27 -04:00
parent 144d02e36c
commit 35530af1fb
8 changed files with 3261 additions and 4 deletions

View file

@ -11,6 +11,7 @@
<script src="resource://zotero-unit/mocha/mocha.js"></script>
<script src="resource://zotero-unit/sinon.js"></script>
<script src="resource://zotero-unit/sinon-as-promised.js"></script>
<script src="resource://zotero-unit/pako_inflate.js"></script>
<script src="support.js" type="application/javascript;version=1.8"></script>
<script src="runtests.js" type="application/javascript;version=1.8"></script>
</body>

View file

@ -281,6 +281,13 @@ function clickOnItemsRow(itemsView, row, button = 0) {
}
/**
* Synchronous inflate
*/
function gunzip(gzdata) {
return pako.inflate(gzdata, { to: 'string' });
}
/**
* Get a default group used by all tests that want one, creating one if necessary

File diff suppressed because it is too large Load diff

View file

@ -5278,6 +5278,11 @@ if (typeof sinon === "undefined") {
this.requestHeaders["Content-Type"] = "text/plain;charset=utf-8";
}
// Added by Zotero
if (this.requestHeaders['Content-Encoding'] == 'gzip') {
data = gunzip(data, true);
}
this.requestBody = data;
}

View file

@ -12,6 +12,18 @@ describe("Zotero.Utilities.Internal", function () {
})
describe("#gzip()/gunzip()", function () {
it("should compress and decompress a Unicode text string", function* () {
var text = "Voilà! \u1F429";
var compstr = yield Zotero.Utilities.Internal.gzip(text);
assert.isAbove(compstr.length, 0);
assert.notEqual(compstr.length, text.length);
var str = yield Zotero.Utilities.Internal.gunzip(compstr);
assert.equal(str, text);
});
});
describe("#delayGenerator", function () {
var spy;