+58
-1
@@ -36,4 +36,15 @@ 'use strict'; | ||
| * @param {Number} [maxPayload=0] The maximum allowed message length | ||
| * @param {Number} [maxBufferedChunks=0] The maximum number of | ||
| * buffered data chunks | ||
| * @param {Number} [maxFragments=0] The maximum number of message | ||
| * fragments | ||
| */ | ||
| constructor(binaryType, extensions, isServer, maxPayload) { | ||
| constructor( | ||
| binaryType, | ||
| extensions, | ||
| isServer, | ||
| maxPayload, | ||
| maxBufferedChunks, | ||
| maxFragments | ||
| ) { | ||
| super(); | ||
@@ -45,2 +56,4 @@ | ||
| this._isServer = !!isServer; | ||
| this._maxBufferedChunks = maxBufferedChunks | 0; | ||
| this._maxFragments = maxFragments | 0; | ||
| this._maxPayload = maxPayload | 0; | ||
@@ -78,2 +91,17 @@ | ||
| if ( | ||
| this._maxBufferedChunks > 0 && | ||
| this._buffers.length >= this._maxBufferedChunks | ||
| ) { | ||
| return cb( | ||
| error( | ||
| RangeError, | ||
| 'Too many buffered chunks', | ||
| false, | ||
| 1008, | ||
| 'WS_ERR_TOO_MANY_BUFFERED_PARTS' | ||
| ) | ||
| ); | ||
| } | ||
| this._bufferedBytes += chunk.length; | ||
@@ -430,2 +458,16 @@ this._buffers.push(chunk); | ||
| if (data.length) { | ||
| if ( | ||
| this._maxFragments > 0 && | ||
| this._fragments.length >= this._maxFragments | ||
| ) { | ||
| this._loop = false; | ||
| return error( | ||
| RangeError, | ||
| 'Too many message fragments', | ||
| false, | ||
| 1008, | ||
| 'WS_ERR_TOO_MANY_BUFFERED_PARTS' | ||
| ); | ||
| } | ||
| // | ||
@@ -469,2 +511,17 @@ // This message is not compressed so its lenght is the sum of the payload | ||
| if ( | ||
| this._maxFragments > 0 && | ||
| this._fragments.length >= this._maxFragments | ||
| ) { | ||
| return cb( | ||
| error( | ||
| RangeError, | ||
| 'Too many message fragments', | ||
| false, | ||
| 1008, | ||
| 'WS_ERR_TOO_MANY_BUFFERED_PARTS' | ||
| ) | ||
| ); | ||
| } | ||
| this._fragments.push(buf); | ||
@@ -471,0 +528,0 @@ } |
@@ -39,2 +39,6 @@ /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^net|tls|https$" }] */ | ||
| * @param {String} [options.host] The hostname where to bind the server | ||
| * @param {Number} [options.maxBufferedChunks=1048576] The maximum number of | ||
| * buffered data chunks | ||
| * @param {Number} [options.maxFragments=131072] The maximum number of message | ||
| * fragments | ||
| * @param {Number} [options.maxPayload=104857600] The maximum allowed message | ||
@@ -56,2 +60,4 @@ * size | ||
| options = { | ||
| maxBufferedChunks: 1024 * 1024, | ||
| maxFragments: 128 * 1024, | ||
| maxPayload: 100 * 1024 * 1024, | ||
@@ -355,3 +361,9 @@ perMessageDeflate: false, | ||
| ws.setSocket(socket, head, this.options.maxPayload); | ||
| ws.setSocket( | ||
| socket, | ||
| head, | ||
| this.options.maxPayload, | ||
| this.options.maxBufferedChunks, | ||
| this.options.maxFragments | ||
| ); | ||
@@ -358,0 +370,0 @@ if (this.clients) { |
+21
-3
@@ -190,5 +190,9 @@ /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Readable$" }] */ | ||
| * @param {Number} [maxPayload=0] The maximum allowed message size | ||
| * @param {Number} [maxBufferedChunks=0] The maximum number of | ||
| * buffered data chunks | ||
| * @param {Number} [maxFragments=0] The maximum number of message | ||
| * fragments | ||
| * @private | ||
| */ | ||
| setSocket(socket, head, maxPayload) { | ||
| setSocket(socket, head, maxPayload, maxBufferedChunks, maxFragments) { | ||
| const receiver = new Receiver( | ||
@@ -198,3 +202,5 @@ this.binaryType, | ||
| this._isServer, | ||
| maxPayload | ||
| maxPayload, | ||
| maxBufferedChunks, | ||
| maxFragments | ||
| ); | ||
@@ -576,2 +582,6 @@ | ||
| * `Sec-WebSocket-Origin` header | ||
| * @param {Number} [options.maxBufferedChunks=1048576] The maximum number of | ||
| * buffered data chunks | ||
| * @param {Number} [options.maxFragments=131072] The maximum number of message | ||
| * fragments | ||
| * @param {Number} [options.maxPayload=104857600] The maximum allowed message | ||
@@ -588,2 +598,4 @@ * size | ||
| protocolVersion: protocolVersions[1], | ||
| maxBufferedChunks: 1024 * 1024, | ||
| maxFragments: 128 * 1024, | ||
| maxPayload: 100 * 1024 * 1024, | ||
@@ -888,3 +900,9 @@ perMessageDeflate: true, | ||
| websocket.setSocket(socket, head, opts.maxPayload); | ||
| websocket.setSocket( | ||
| socket, | ||
| head, | ||
| opts.maxPayload, | ||
| opts.maxBufferedChunks, | ||
| opts.maxFragments | ||
| ); | ||
| }); | ||
@@ -891,0 +909,0 @@ } |
+1
-1
| { | ||
| "name": "ws", | ||
| "version": "7.5.10", | ||
| "version": "7.5.11", | ||
| "description": "Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
124596
1.87%3640
2.36%