websocket-driver
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -0,1 +1,7 @@ | ||
### 0.3.1 / 2013-12-03 | ||
* Add a `maxLength` option to limit allowed frame size | ||
* Don't pre-allocate a message buffer until the whole frame has arrived | ||
* Fix compatibility with Node v0.11 `HTTPParser` | ||
### 0.3.0 / 2013-09-09 | ||
@@ -2,0 +8,0 @@ |
@@ -25,4 +25,4 @@ var HTTPParser = process.binding('http_parser').HTTPParser, | ||
this._parser.onHeadersComplete = function(info) { | ||
self.method = info.method; | ||
this._parser.onHeadersComplete = this._parser[HTTPParser.kOnHeadersComplete] = function(info) { | ||
self.method = (typeof info.method === 'number') ? HttpParser.METHODS[info.method] : info.method; | ||
self.statusCode = info.statusCode; | ||
@@ -38,3 +38,3 @@ self.url = info.url; | ||
this._parser.onMessageComplete = function() { | ||
this._parser.onMessageComplete = this._parser[HTTPParser.kOnMessageComplete] = function() { | ||
self._complete = true; | ||
@@ -44,2 +44,26 @@ }; | ||
HttpParser.METHODS = { | ||
0: 'DELETE', | ||
1: 'GET', | ||
2: 'HEAD', | ||
3: 'POST', | ||
4: 'PUT', | ||
5: 'CONNECT', | ||
6: 'OPTIONS', | ||
7: 'TRACE', | ||
8: 'COPY', | ||
9: 'LOCK', | ||
10: 'MKCOL', | ||
11: 'MOVE', | ||
12: 'PROPFIND', | ||
13: 'PROPPATCH', | ||
14: 'SEARCH', | ||
15: 'UNLOCK', | ||
16: 'REPORT', | ||
17: 'MKACTIVITY', | ||
18: 'CHECKOUT', | ||
19: 'MERGE', | ||
24: 'PATCH' | ||
}; | ||
HttpParser.prototype.isComplete = function() { | ||
@@ -46,0 +70,0 @@ return this._complete; |
@@ -14,2 +14,3 @@ var crypto = require('crypto'), | ||
this._protocols = this._options.protocols || []; | ||
this._maxLength = this._options.maxLength || this.MAX_LENGTH; | ||
@@ -70,3 +71,5 @@ if (typeof this._protocols === 'string') | ||
MAX_LENGTH: Math.pow(2, 53) - 1, | ||
// This is the maximum length of a Node buffer: | ||
// https://github.com/joyent/node/blob/master/src/smalloc.h#L40 | ||
MAX_LENGTH: 0x3fffffff, | ||
TWO_POWERS: [0, 1, 2, 3, 4, 5, 6, 7].map(function(n) { return Math.pow(2, 8 * n) }), | ||
@@ -308,3 +311,3 @@ | ||
if (this._length > this.MAX_LENGTH) | ||
if (this._length > this._maxLength) | ||
return this._fail('too_large', 'WebSocket frame length too large'); | ||
@@ -311,0 +314,0 @@ |
var StreamReader = function() { | ||
this._queue = []; | ||
this._cursor = 0; | ||
this._queue = []; | ||
this._queueSize = 0; | ||
this._cursor = 0; | ||
}; | ||
@@ -14,5 +15,8 @@ | ||
this._queue.push(buffer); | ||
this._queueSize += buffer.length; | ||
}; | ||
StreamReader.prototype._readBuffer = function(length) { | ||
if (length > this._queueSize) return null; | ||
var buffer = new Buffer(length), | ||
@@ -33,7 +37,6 @@ queue = this._queue, | ||
remain -= size; | ||
this._queueSize -= size; | ||
i += 1; | ||
} | ||
if (remain > 0) return null; | ||
queue.splice(0, i-1); | ||
@@ -40,0 +43,0 @@ this._cursor = (i === 1 ? this._cursor : 0) + size; |
@@ -8,3 +8,3 @@ { "name" : "websocket-driver" | ||
, "version" : "0.3.0" | ||
, "version" : "0.3.1" | ||
, "engines" : {"node": ">=0.4.0"} | ||
@@ -11,0 +11,0 @@ , "main" : "./lib/websocket/driver" |
@@ -176,2 +176,4 @@ # websocket-driver [![Build Status](https://travis-ci.org/faye/websocket-driver-node.png)](https://travis-ci.org/faye/websocket-driver-node) | ||
* `maxLength` - the maximum allowed size of incoming message frames, in bytes. | ||
The default value is `2^30 - 1`, or 1 byte short of 1 GiB. | ||
* `protocols` - an array of strings representing acceptable subprotocols for | ||
@@ -178,0 +180,0 @@ use over the socket. The driver will negotiate one of these to use via the |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50482
1066
308