Skip to content

Commit

Permalink
[fix] Recreate the inflate stream if it ends
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Mar 6, 2021
1 parent cbff929 commit 9277437
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/permessage-deflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,16 @@ class PerMessageDeflate {
this._inflate[kTotalLength]
);

this._inflate[kTotalLength] = 0;
this._inflate[kBuffers] = [];
if (this._inflate._readableState.endEmitted) {
this._inflate.close();
this._inflate = null;
} else {
this._inflate[kTotalLength] = 0;
this._inflate[kBuffers] = [];

if (fin && this.params[`${endpoint}_no_context_takeover`]) {
this._inflate.reset();
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
this._inflate.reset();
}
}

callback(null, data);
Expand Down
21 changes: 21 additions & 0 deletions test/permessage-deflate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,5 +631,26 @@ describe('PerMessageDeflate', () => {

process.nextTick(() => perMessageDeflate.cleanup());
});

it('recreates the inflate stream if it ends', (done) => {
const perMessageDeflate = new PerMessageDeflate();
const extensions = extension.parse(
'permessage-deflate; client_no_context_takeover; ' +
'server_no_context_takeover'
);
const buf = Buffer.from('33343236313533b7000000', 'hex');
const expected = Buffer.from('12345678');

perMessageDeflate.accept(extensions['permessage-deflate']);

perMessageDeflate.decompress(buf, true, (err, data) => {
assert.ok(data.equals(expected));

perMessageDeflate.decompress(buf, true, (err, data) => {
assert.ok(data.equals(expected));
done();
});
});
});
});
});

0 comments on commit 9277437

Please sign in to comment.