Skip to content

Commit

Permalink
[fix] Handle close frame which spans multiple packets (#1494)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwm-twx authored and lpinca committed Jan 23, 2019
1 parent c61218f commit 3df4809
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/receiver.js
Expand Up @@ -62,7 +62,7 @@ class Receiver extends stream.Writable {
* @param {Function} cb Callback
*/
_write(chunk, encoding, cb) {
if (this._opcode === 0x08) return cb();
if (this._opcode === 0x08 && this._state == GET_INFO) return cb();

this._bufferedBytes += chunk.length;
this._buffers.push(chunk);
Expand Down Expand Up @@ -454,6 +454,7 @@ class Receiver extends stream.Writable {
this.end();
}

this._state = GET_INFO;
return;
}

Expand Down
13 changes: 13 additions & 0 deletions test/receiver.test.js
Expand Up @@ -34,6 +34,19 @@ describe('Receiver', function() {
receiver.write(Buffer.from('8800', 'hex'));
});

it('parses a close message spanning multiple writes', function(done) {
const receiver = new Receiver();

receiver.on('conclude', (code, data) => {
assert.strictEqual(code, 1000);
assert.strictEqual(data, 'DONE');
done();
});

receiver.write(Buffer.from('8806', 'hex'));
receiver.write(Buffer.from('03e8444F4E45', 'hex'));
});

it('parses a masked text message', function(done) {
const receiver = new Receiver();

Expand Down

0 comments on commit 3df4809

Please sign in to comment.