Skip to content

Commit

Permalink
[fix] Use Object.assign() for send() options (#968)
Browse files Browse the repository at this point in the history
This avoids mutating the passed in arguments.
  • Loading branch information
Tom Atkinson authored and lpinca committed Jan 14, 2017
1 parent 7bec220 commit bd41a05
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/WebSocket.js
Expand Up @@ -355,16 +355,18 @@ class WebSocket extends EventEmitter {
if (typeof data === 'number') data = data.toString();
else if (!data) data = '';

options = options || {};
if (options.fin !== false) options.fin = true;
if (options.binary === undefined) options.binary = typeof data !== 'string';
if (options.mask === undefined) options.mask = !this._isServer;
if (options.compress === undefined) options.compress = true;
const opts = Object.assign({
fin: true,
binary: typeof data !== 'string',
mask: !this._isServer,
compress: true
}, options);

if (!this.extensions[PerMessageDeflate.extensionName]) {
options.compress = false;
opts.compress = false;
}

this._sender.send(data, options, cb);
this._sender.send(data, opts, cb);
}

/**
Expand Down

0 comments on commit bd41a05

Please sign in to comment.