Socket
Socket
Sign inDemoInstall

websocket-driver

Package Overview
Dependencies
1
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.6.0 to 0.6.1

5

CHANGELOG.md

@@ -0,1 +1,6 @@

### 0.6.1 / 2015-07-13
* Use the `buffer.{read,write}UInt{16,32}BE` methods for reading/writing numbers
to buffers rather than including duplicate logic for this
### 0.6.0 / 2015-07-08

@@ -2,0 +7,0 @@

6

lib/websocket/driver/client.js

@@ -55,7 +55,7 @@ 'use strict';

parse: function(data) {
parse: function(chunk) {
if (this.readyState === 3) return;
if (this.readyState > 0) return Hybi.prototype.parse.call(this, data);
if (this.readyState > 0) return Hybi.prototype.parse.call(this, chunk);
this._http.parse(data);
this._http.parse(chunk);
if (!this._http.isComplete()) return;

@@ -62,0 +62,0 @@

@@ -8,3 +8,3 @@ 'use strict';

Base.apply(this, arguments);
this._stage = 0;
this._stage = 0;
this.version = 'hixie-75';

@@ -27,13 +27,13 @@

parse: function(buffer) {
parse: function(chunk) {
if (this.readyState > 1) return;
this._reader.put(buffer);
this._reader.put(chunk);
this._reader.eachByte(function(data) {
var message, value;
this._reader.eachByte(function(octet) {
var message;
switch (this._stage) {
case -1:
this._body.push(data);
this._body.push(octet);
this._sendHandshakeBody();

@@ -43,8 +43,7 @@ break;

case 0:
this._parseLeadingByte(data);
this._parseLeadingByte(octet);
break;
case 1:
value = (data & 0x7F);
this._length = value + 128 * this._length;
this._length = (octet & 0x7F) + 128 * this._length;

@@ -54,3 +53,3 @@ if (this._closing && this._length === 0) {

}
else if ((0x80 & data) !== 0x80) {
else if ((octet & 0x80) !== 0x80) {
if (this._length === 0) {

@@ -61,3 +60,3 @@ this._stage = 0;

this._skipped = 0;
this._stage = 2;
this._stage = 2;
}

@@ -68,3 +67,3 @@ }

case 2:
if (data === 0xFF) {
if (octet === 0xFF) {
this._stage = 0;

@@ -80,3 +79,3 @@ message = new Buffer(this._buffer).toString('utf8', 0, this._buffer.length);

} else {
this._buffer.push(data);
this._buffer.push(octet);
if (this._buffer.length > this._maxLength) return this.close();

@@ -90,12 +89,12 @@ }

frame: function(data) {
if (this.readyState === 0) return this._queue([data]);
frame: function(buffer) {
if (this.readyState === 0) return this._queue([buffer]);
if (this.readyState > 1) return false;
var buffer = new Buffer(data, 'utf8'),
frame = new Buffer(buffer.length + 2);
var payload = new Buffer(buffer, 'utf8'),
frame = new Buffer(payload.length + 2);
frame[0] = 0x00;
frame[buffer.length + 1] = 0xFF;
buffer.copy(frame, 1);
frame[payload.length + 1] = 0xFF;
payload.copy(frame, 1);

@@ -113,6 +112,6 @@ this._write(frame);

_parseLeadingByte: function(data) {
if ((0x80 & data) === 0x80) {
_parseLeadingByte: function(octet) {
if ((octet & 0x80) === 0x80) {
this._length = 0;
this._stage = 1;
this._stage = 1;
} else {

@@ -122,3 +121,3 @@ delete this._length;

this._buffer = [];
this._stage = 2;
this._stage = 2;
}

@@ -125,0 +124,0 @@ }

@@ -17,11 +17,3 @@ 'use strict';

var bigEndian = function(number) {
var string = '';
[24, 16, 8, 0].forEach(function(offset) {
string += String.fromCharCode(number >> offset & 0xFF);
});
return string;
};
var Draft76 = function(request, url, options) {

@@ -69,3 +61,2 @@ Draft75.apply(this, arguments);

if (this._body.length < this.BODY_SIZE) return null;
var body = new Buffer(this._body.slice(0, this.BODY_SIZE));

@@ -77,8 +68,10 @@ var headers = this._request.headers,

value2 = numberFromKey(key2) / spacesInKey(key2),
md5 = crypto.createHash('md5');
md5 = crypto.createHash('md5'),
buffer = new Buffer(8 + this.BODY_SIZE);
md5.update(bigEndian(value1));
md5.update(bigEndian(value2));
md5.update(body.toString('binary'));
buffer.writeUInt32BE(value1, 0);
buffer.writeUInt32BE(value2, 4);
new Buffer(this._body).copy(buffer, 8, 0, this.BODY_SIZE);
md5.update(buffer);
return new Buffer(md5.digest('binary'), 'binary');

@@ -100,5 +93,5 @@ },

_parseLeadingByte: function(data) {
if (data !== 0xFF)
return Draft75.prototype._parseLeadingByte.call(this, data);
_parseLeadingByte: function(octet) {
if (octet !== 0xFF)
return Draft75.prototype._parseLeadingByte.call(this, octet);

@@ -105,0 +98,0 @@ this._closing = true;

@@ -63,10 +63,9 @@ 'use strict';

var instance = {
BYTE: 255,
FIN: 128,
MASK: 128,
RSV1: 64,
RSV2: 32,
RSV3: 16,
OPCODE: 15,
LENGTH: 127,
FIN: 0x80,
MASK: 0x80,
RSV1: 0x40,
RSV2: 0x20,
RSV3: 0x10,
OPCODE: 0x0F,
LENGTH: 0x7F,

@@ -86,4 +85,2 @@ OPCODES: {

TWO_POWERS: [0, 1, 2, 3, 4, 5, 6, 7].map(function(n) { return Math.pow(2, 8 * n) }),
ERRORS: {

@@ -113,4 +110,4 @@ normal_closure: 1000,

parse: function(data) {
this._reader.put(data);
parse: function(chunk) {
this._reader.put(chunk);
var buffer = true;

@@ -196,11 +193,11 @@ while (buffer) {

frame: function(data, type, code) {
if (this.readyState <= 0) return this._queue([data, type, code]);
frame: function(buffer, type, code) {
if (this.readyState <= 0) return this._queue([buffer, type, code]);
if (this.readyState > 2) return false;
if (data instanceof Array) data = new Buffer(data);
if (buffer instanceof Array) buffer = new Buffer(buffer);
var message = new Message(),
isText = (typeof data === 'string'),
payload, buffer;
isText = (typeof buffer === 'string'),
payload, copy;

@@ -210,10 +207,9 @@ message.rsv1 = message.rsv2 = message.rsv3 = false;

payload = isText ? new Buffer(data, 'utf8') : data;
payload = isText ? new Buffer(buffer, 'utf8') : buffer;
if (code) {
buffer = payload;
payload = new Buffer(2 + buffer.length);
payload[0] = ~~(code / 256) & this.BYTE;
payload[1] = code & this.BYTE;
buffer.copy(payload, 2);
copy = payload;
payload = new Buffer(2 + copy.length);
payload.writeUInt16BE(code, 0);
copy.copy(payload, 2);
}

@@ -255,3 +251,2 @@ message.data = payload;

buffer = new Buffer(offset + length),
BYTE = this.BYTE,
masked = frame.masked ? this.MASK : 0;

@@ -269,14 +264,7 @@

buffer[1] = masked | 126;
buffer[2] = ~~(length / 256);
buffer[3] = length & BYTE;
buffer.writeUInt16BE(length, 2);
} else {
buffer[1] = masked | 127;
buffer[2] = ~~(length / Math.pow(2, 56)) & BYTE;
buffer[3] = ~~(length / Math.pow(2, 48)) & BYTE;
buffer[4] = ~~(length / Math.pow(2, 40)) & BYTE;
buffer[5] = ~~(length / Math.pow(2, 32)) & BYTE;
buffer[6] = ~~(length / Math.pow(2, 24)) & BYTE;
buffer[7] = ~~(length / Math.pow(2, 16)) & BYTE;
buffer[8] = ~~(length / Math.pow(2, 8)) & BYTE;
buffer[9] = length & BYTE;
buffer.writeUInt32BE(Math.floor(length / 0x100000000), 2);
buffer.writeUInt32BE(length % 0x100000000, 6);
}

@@ -330,5 +318,5 @@

_parseOpcode: function(data) {
_parseOpcode: function(octet) {
var rsvs = [this.RSV1, this.RSV2, this.RSV3].map(function(rsv) {
return (data & rsv) === rsv;
return (octet & rsv) === rsv;
});

@@ -338,7 +326,7 @@

frame.final = (data & this.FIN) === this.FIN;
frame.final = (octet & this.FIN) === this.FIN;
frame.rsv1 = rsvs[0];
frame.rsv2 = rsvs[1];
frame.rsv3 = rsvs[2];
frame.opcode = (data & this.OPCODE);
frame.opcode = (octet & this.OPCODE);

@@ -363,6 +351,6 @@ this._stage = 1;

_parseLength: function(data) {
_parseLength: function(octet) {
var frame = this._frame;
frame.masked = (data & this.MASK) === this.MASK;
frame.length = (data & this.LENGTH);
frame.masked = (octet & this.MASK) === this.MASK;
frame.length = (octet & this.LENGTH);

@@ -383,3 +371,3 @@ if (frame.length >= 0 && frame.length <= 125) {

var frame = this._frame;
frame.length = this._getInteger(buffer);
frame.length = this._readUInt(buffer);

@@ -484,7 +472,7 @@ this._stage = frame.masked ? 3 : 4;

_getInteger: function(bytes) {
var number = 0;
for (var i = 0, n = bytes.length; i < n; i++)
number += bytes[i] * this.TWO_POWERS[n - 1 - i];
return number;
_readUInt: function(buffer) {
if (buffer.length === 2) return buffer.readUInt16BE(0);
return buffer.readUInt32BE(0) * 0x100000000 +
buffer.readUInt32BE(4);
}

@@ -491,0 +479,0 @@ };

@@ -24,6 +24,6 @@ 'use strict';

parse: function(data) {
if (this._delegate) return this._delegate.parse(data);
parse: function(chunk) {
if (this._delegate) return this._delegate.parse(chunk);
this._http.parse(data);
this._http.parse(chunk);
if (!this._http.isComplete()) return;

@@ -30,0 +30,0 @@

@@ -90,9 +90,9 @@ 'use strict';

HttpParser.prototype.parse = function(data) {
HttpParser.prototype.parse = function(chunk) {
var offset = (version < 6) ? 1 : 0,
consumed = this._parser.execute(data, 0, data.length) + offset;
consumed = this._parser.execute(chunk, 0, chunk.length) + offset;
if (this._complete)
this.body = (consumed < data.length)
? data.slice(consumed)
this.body = (consumed < chunk.length)
? chunk.slice(consumed)
: new Buffer(0);

@@ -99,0 +99,0 @@ };

@@ -8,3 +8,3 @@ { "name" : "websocket-driver"

, "version" : "0.6.0"
, "version" : "0.6.1"
, "engines" : {"node": ">=0.6.0"}

@@ -11,0 +11,0 @@ , "main" : "./lib/websocket/driver"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc