Skip to content

Commit

Permalink
[fix] Do not override the fin option of the send method
Browse files Browse the repository at this point in the history
  • Loading branch information
codingphil authored and lpinca committed Oct 21, 2016
1 parent 78425d0 commit ea50be7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/WebSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ WebSocket.prototype.send = function send (data, options, cb) {
}

options = options || {};
options.fin = true;
if (options.fin !== false) options.fin = true;

if (typeof options.binary === 'undefined') {
options.binary = (data instanceof ArrayBuffer || data instanceof Buffer ||
Expand Down
18 changes: 18 additions & 0 deletions test/WebSocket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,24 @@ describe('WebSocket', function() {
});
});

it('does not override the `fin` option', function (done) {
const wss = new WebSocketServer({ port: ++port }, () => {
const ws = new WebSocket(`ws://localhost:${port}`);

ws.on('open', () => {
ws.send('fragment', { fin: false });
ws.send('fragment', { fin: true });
});
});

wss.on('connection', (ws) => {
ws.on('message', (msg) => {
assert.strictEqual(msg, 'fragmentfragment');
wss.close(done);
});
});
});

it('send and receive binary data as an array', function(done) {
server.createServer(++port, function(srv) {
var ws = new WebSocket('ws://localhost:' + port);
Expand Down

0 comments on commit ea50be7

Please sign in to comment.