Update permessage-deflate.js

This commit is contained in:
ZyLacx 2021-12-27 17:16:01 +01:00
parent f5c71c06a9
commit e24cad5c6a

View file

@ -29,24 +29,26 @@ class PerMessageDeflate {
/** /**
* Creates a PerMessageDeflate instance. * Creates a PerMessageDeflate instance.
* *
* @param {Object} options Configuration options * @param {Object} [options] Configuration options
* @param {Boolean} options.serverNoContextTakeover Request/accept disabling * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
* of server context takeover * disabling of server context takeover
* @param {Boolean} options.clientNoContextTakeover Advertise/acknowledge * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
* disabling of client context takeover * acknowledge disabling of client context takeover
* @param {(Boolean|Number)} options.serverMaxWindowBits Request/confirm the * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
* use of a custom server window size * use of a custom server window size
* @param {(Boolean|Number)} options.clientMaxWindowBits Advertise support * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
* for, or request, a custom client window size * for, or request, a custom client window size
* @param {Object} options.zlibDeflateOptions Options to pass to zlib on deflate * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
* @param {Object} options.zlibInflateOptions Options to pass to zlib on inflate * deflate
* @param {Number} options.threshold Size (in bytes) below which messages * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
* should not be compressed * inflate
* @param {Number} options.concurrencyLimit The number of concurrent calls to * @param {Number} [options.threshold=1024] Size (in bytes) below which
* zlib * messages should not be compressed
* @param {Boolean} isServer Create the instance in either server or client * @param {Number} [options.concurrencyLimit=10] The number of concurrent
* mode * calls to zlib
* @param {Number} maxPayload The maximum allowed message length * @param {Boolean} [isServer=false] Create the instance in either server or
* client mode
* @param {Number} [maxPayload=0] The maximum allowed message length
*/ */
constructor(options, isServer, maxPayload) { constructor(options, isServer, maxPayload) {
this._maxPayload = maxPayload | 0; this._maxPayload = maxPayload | 0;
@ -374,12 +376,16 @@ class PerMessageDeflate {
this._inflate[kTotalLength] this._inflate[kTotalLength]
); );
if (fin && this.params[`${endpoint}_no_context_takeover`]) { if (this._inflate._readableState.endEmitted) {
this._inflate.close(); this._inflate.close();
this._inflate = null; this._inflate = null;
} else { } else {
this._inflate[kTotalLength] = 0; this._inflate[kTotalLength] = 0;
this._inflate[kBuffers] = []; this._inflate[kBuffers] = [];
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
this._inflate.reset();
}
} }
callback(null, data); callback(null, data);
@ -446,12 +452,11 @@ class PerMessageDeflate {
// //
this._deflate[kCallback] = null; this._deflate[kCallback] = null;
this._deflate[kTotalLength] = 0;
this._deflate[kBuffers] = [];
if (fin && this.params[`${endpoint}_no_context_takeover`]) { if (fin && this.params[`${endpoint}_no_context_takeover`]) {
this._deflate.close(); this._deflate.reset();
this._deflate = null;
} else {
this._deflate[kTotalLength] = 0;
this._deflate[kBuffers] = [];
} }
callback(null, data); callback(null, data);
@ -490,6 +495,7 @@ function inflateOnData(chunk) {
} }
this[kError] = new RangeError('Max payload size exceeded'); this[kError] = new RangeError('Max payload size exceeded');
this[kError].code = 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH';
this[kError][kStatusCode] = 1009; this[kError][kStatusCode] = 1009;
this.removeListener('data', inflateOnData); this.removeListener('data', inflateOnData);
this.reset(); this.reset();