Comparing version 0.4.31 to 0.4.32
@@ -56,3 +56,3 @@ /*! | ||
self.messageEnd = 0; | ||
self.state = BINARYLENGTH; | ||
self.state = BINARYLENGTH; | ||
data = data.slice(1); | ||
@@ -87,3 +87,3 @@ } else { | ||
if (data.length >= dataleft) { | ||
// consume the whole buffer to finish the frame | ||
// consume the whole buffer to finish the frame | ||
self.buffers.push(data); | ||
@@ -107,3 +107,3 @@ self.spanLength += dataleft; | ||
while(data) data = doAdd(); | ||
} | ||
}; | ||
@@ -120,3 +120,3 @@ /** | ||
this.buffers = []; | ||
} | ||
}; | ||
@@ -147,3 +147,3 @@ /** | ||
return tail; | ||
} | ||
}; | ||
@@ -160,3 +160,3 @@ /** | ||
return this; | ||
} | ||
}; | ||
@@ -175,3 +175,3 @@ /** | ||
this.spanLength = 0; | ||
} | ||
}; | ||
@@ -178,0 +178,0 @@ /** |
@@ -14,8 +14,2 @@ /*! | ||
/** | ||
* Node version 0.4 and 0.6 compatibility | ||
*/ | ||
var isNodeV4 = /^v0\.4/.test(process.version); | ||
/** | ||
* HyBi Receiver implementation | ||
@@ -67,3 +61,3 @@ */ | ||
this.onpong = function() {}; | ||
}; | ||
} | ||
@@ -97,3 +91,3 @@ module.exports = Receiver; | ||
} | ||
} | ||
}; | ||
@@ -122,3 +116,3 @@ /** | ||
this.onpong = null; | ||
} | ||
}; | ||
@@ -147,3 +141,3 @@ /** | ||
} | ||
} | ||
}; | ||
@@ -172,3 +166,3 @@ /** | ||
} | ||
} | ||
}; | ||
@@ -181,5 +175,5 @@ /** | ||
Receiver.prototype.allocateFromPool = !isNodeV4 | ||
? function(length, isFragmented) { return (isFragmented ? this.fragmentedBufferPool : this.unfragmentedBufferPool).get(length); } | ||
: function(length) { return new Buffer(length); }; | ||
Receiver.prototype.allocateFromPool = function(length, isFragmented) { | ||
return (isFragmented ? this.fragmentedBufferPool : this.unfragmentedBufferPool).get(length); | ||
}; | ||
@@ -226,3 +220,3 @@ /** | ||
} | ||
} | ||
}; | ||
@@ -249,3 +243,3 @@ /** | ||
this.expectHeader(2, this.processPacket); | ||
} | ||
}; | ||
@@ -274,3 +268,3 @@ /** | ||
this.currentMessage = []; | ||
} | ||
}; | ||
@@ -287,3 +281,3 @@ /** | ||
return buf != null ? buf.toString('utf8') : ''; | ||
} | ||
}; | ||
@@ -302,3 +296,3 @@ /** | ||
return mergedBuffer; | ||
} | ||
}; | ||
@@ -315,3 +309,3 @@ /** | ||
return this; | ||
} | ||
}; | ||
@@ -318,0 +312,0 @@ /** |
@@ -37,8 +37,3 @@ /*! | ||
if (this.isClosed) return; | ||
/* | ||
if (options && options.binary) { | ||
this.error('hixie websockets do not support binary'); | ||
return; | ||
} | ||
*/ | ||
var isString = typeof data == 'string' | ||
@@ -56,3 +51,3 @@ , length = isString ? Buffer.byteLength(data) : data.length | ||
// assume length less than 2**14 bytes | ||
if (lengthbytes > 1) | ||
if (lengthbytes > 1) | ||
buffer.write(String.fromCharCode(128+length/128), offset++, 'binary'); | ||
@@ -70,3 +65,3 @@ buffer.write(String.fromCharCode(length&0x7f), offset++, 'binary'); | ||
// sending binary, not writing end marker | ||
} else | ||
} else | ||
buffer.write('\xff', offset + length, 'binary'); | ||
@@ -82,3 +77,3 @@ this.continuationFrame = false; | ||
} | ||
} | ||
}; | ||
@@ -100,3 +95,3 @@ /** | ||
} | ||
} | ||
}; | ||
@@ -109,3 +104,3 @@ /** | ||
Sender.prototype.ping = function(data, options) {} | ||
Sender.prototype.ping = function(data, options) {}; | ||
@@ -118,3 +113,3 @@ /** | ||
Sender.prototype.pong = function(data, options) {} | ||
Sender.prototype.pong = function(data, options) {}; | ||
@@ -130,2 +125,2 @@ /** | ||
return this; | ||
} | ||
}; |
@@ -44,3 +44,3 @@ /*! | ||
this.frameAndSend(0x8, dataBuffer, true, mask); | ||
} | ||
}; | ||
@@ -56,3 +56,3 @@ /** | ||
this.frameAndSend(0x9, data || '', true, mask); | ||
} | ||
}; | ||
@@ -68,3 +68,3 @@ /** | ||
this.frameAndSend(0xa, data || '', true, mask); | ||
} | ||
}; | ||
@@ -85,3 +85,3 @@ /** | ||
this.frameAndSend(opcode, data, finalFragment, mask, cb); | ||
} | ||
}; | ||
@@ -196,3 +196,3 @@ /** | ||
} | ||
} | ||
}; | ||
@@ -199,0 +199,0 @@ module.exports = Sender; |
@@ -13,3 +13,3 @@ /*! | ||
, url = require('url') | ||
, fs = require('fs') | ||
, stream = require('stream') | ||
, Options = require('options') | ||
@@ -34,8 +34,2 @@ , Sender = require('./Sender') | ||
/** | ||
* Node version 0.4 and 0.6 compatibility | ||
*/ | ||
var isNodeV4 = /^v0\.4/.test(process.version); | ||
/** | ||
* WebSocket implementation | ||
@@ -212,3 +206,4 @@ */ | ||
if (typeof options.mask == 'undefined') options.mask = !this._isServer; | ||
if (data instanceof fs.ReadStream) { | ||
var readable = typeof stream.Readable == 'function' ? stream.Readable : stream.Stream; | ||
if (data instanceof readable) { | ||
startQueue(this); | ||
@@ -504,10 +499,2 @@ var self = this; | ||
var agent = options.value.agent; | ||
// node<=v0.4.x compatibility | ||
if (!agent && isNodeV4) { | ||
isNodeV4 = true; | ||
agent = new httpObj.Agent({ | ||
host: serverUrl.hostname, | ||
port: port | ||
}); | ||
} | ||
@@ -564,6 +551,2 @@ var headerHost = serverUrl.hostname; | ||
if (isNodeV4) { | ||
throw new Error('Client side certificates are not supported on Node 0.4.x'); | ||
} | ||
if (options.isDefinedAndNonNull('pfx')) requestOptions.pfx = options.value.pfx; | ||
@@ -583,6 +566,3 @@ if (options.isDefinedAndNonNull('key')) requestOptions.key = options.value.key; | ||
if (isNodeV4) { | ||
requestOptions.path = (serverUrl.pathname || '/') + (serverUrl.search || ''); | ||
} | ||
else requestOptions.path = serverUrl.path || '/'; | ||
requestOptions.path = serverUrl.path || '/'; | ||
@@ -604,16 +584,21 @@ if (agent) { | ||
(isNodeV4 ? agent : req).on('error', function(error) { | ||
req.on('error', function(error) { | ||
self.emit('error', error); | ||
cleanupWebsocketResources.call(this, error); | ||
}); | ||
(isNodeV4 ? agent : req).once('response', function(res) { | ||
var error = new Error('unexpected server response (' + res.statusCode + ')'); | ||
self.emit('error', error); | ||
req.once('response', function(res) { | ||
if (!self.emit('unexpected-response', req, res)) { | ||
var error = new Error('unexpected server response (' + res.statusCode + ')'); | ||
req.abort(); | ||
self.emit('error', error); | ||
} | ||
cleanupWebsocketResources.call(this, error); | ||
}); | ||
(isNodeV4 ? agent : req).once('upgrade', function(res, socket, upgradeHead) { | ||
req.once('upgrade', function(res, socket, upgradeHead) { | ||
if (self.readyState == WebSocket.CLOSED) { | ||
// client closed before server accepted connection | ||
self.emit('close'); | ||
removeAllListeners(self); | ||
self.removeAllListeners(); | ||
socket.end(); | ||
@@ -625,3 +610,3 @@ return; | ||
self.emit('error', 'invalid server key'); | ||
removeAllListeners(self); | ||
self.removeAllListeners(); | ||
socket.end(); | ||
@@ -643,3 +628,3 @@ return; | ||
self.emit('error', protError); | ||
removeAllListeners(self); | ||
self.removeAllListeners(); | ||
socket.end(); | ||
@@ -654,3 +639,3 @@ return; | ||
// perform cleanup on http resources | ||
removeAllListeners(isNodeV4 ? agent : req); | ||
req.removeAllListeners(); | ||
req = null; | ||
@@ -795,3 +780,3 @@ agent = null; | ||
if (this._socket) { | ||
removeAllListeners(this._socket); | ||
this._socket.removeAllListeners(); | ||
// catch all socket error after removing all standard handlers | ||
@@ -810,3 +795,3 @@ var socket = this._socket; | ||
if (this._sender) { | ||
removeAllListeners(this._sender); | ||
this._sender.removeAllListeners(); | ||
this._sender = null; | ||
@@ -818,14 +803,5 @@ } | ||
} | ||
removeAllListeners(this); | ||
this.removeAllListeners(); | ||
this.on('error', function() {}); // catch all errors after this | ||
delete this._queue; | ||
} | ||
function removeAllListeners(instance) { | ||
if (isNodeV4) { | ||
// node v4 doesn't *actually* remove all listeners globally, | ||
// so we do that instead | ||
instance._events = {}; | ||
} | ||
else instance.removeAllListeners(); | ||
} |
@@ -11,3 +11,2 @@ /*! | ||
, crypto = require('crypto') | ||
, url = require('url') | ||
, Options = require('options') | ||
@@ -47,3 +46,3 @@ , WebSocket = require('./WebSocket') | ||
this._server.listen(options.value.port, options.value.host, callback); | ||
this._closeServer = function() { self._server.close(); }; | ||
this._closeServer = function() { if (self._server) self._server.close(); }; | ||
} | ||
@@ -278,4 +277,7 @@ else if (options.value.server) { | ||
if (this.options.verifyClient.length == 2) { | ||
this.options.verifyClient(info, function(result) { | ||
if (!result) abortConnection(socket, 401, 'Unauthorized') | ||
this.options.verifyClient(info, function(result, code, name) { | ||
if (typeof code === 'undefined') code = 401; | ||
if (typeof name === 'undefined') name = http.STATUS_CODES[code]; | ||
if (!result) abortConnection(socket, code, name); | ||
else completeHybiUpgrade1(); | ||
@@ -434,4 +436,7 @@ }); | ||
var self = this; | ||
this.options.verifyClient(info, function(result) { | ||
if (!result) abortConnection(socket, 401, 'Unauthorized') | ||
this.options.verifyClient(info, function(result, code, name) { | ||
if (typeof code === 'undefined') code = 401; | ||
if (typeof name === 'undefined') name = http.STATUS_CODES[code]; | ||
if (!result) abortConnection(socket, code, name); | ||
else onClientVerified.apply(self); | ||
@@ -438,0 +443,0 @@ }); |
@@ -5,3 +5,3 @@ { | ||
"description": "simple to use, blazing fast and thoroughly tested websocket client, server and console for node.js, up-to-date against RFC-6455", | ||
"version": "0.4.31", | ||
"version": "0.4.32", | ||
"keywords": [ | ||
@@ -31,4 +31,4 @@ "Hixie", | ||
"dependencies": { | ||
"commander": "~0.6.1", | ||
"nan": "~0.3.0", | ||
"commander": "~2.1.0", | ||
"nan": "~1.0.0", | ||
"tinycolor": "0.x", | ||
@@ -35,0 +35,0 @@ "options": ">=0.0.5" |
@@ -125,3 +125,3 @@ [![Build Status](https://secure.travis-ci.org/einaros/ws.png)](http://travis-ci.org/einaros/ws) | ||
$ npm install -g ws | ||
$ wscat -c ws://echo.websocket.org -p 8 | ||
$ wscat -c ws://echo.websocket.org | ||
connected (press CTRL+C to quit) | ||
@@ -128,0 +128,0 @@ > hi there |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
5
107764
25
2337
+ Addedcommander@2.1.0(transitive)
+ Addednan@1.0.0(transitive)
- Removedcommander@0.6.1(transitive)
- Removednan@0.3.2(transitive)
Updatedcommander@~2.1.0
Updatednan@~1.0.0