From 1ec0b0aed5cc002449ce27905313fdaef06bbf55 Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Wed, 22 Nov 2023 00:39:38 -0300 Subject: [PATCH] optimize: PWSL parseFrameHeader This commit optimizes PWSL by removing unecessary code, as servers must not mask their data. --- src/ws.js | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/src/ws.js b/src/ws.js index 782ea16..39d0538 100644 --- a/src/ws.js +++ b/src/ws.js @@ -11,7 +11,6 @@ function parseFrameHeader(buffer) { const opcode = buffer[0] & 0b00001111 const fin = (buffer[0] & 0b10000000) == 0b10000000 - const isMasked = (buffer[1] & 0x80) == 0x80 let payloadLength = buffer[1] & 0b01111111 if (payloadLength == 126) { @@ -24,20 +23,7 @@ function parseFrameHeader(buffer) { startIndex += 8 } - let mask = null - - if (isMasked) { - mask = buffer.subarray(startIndex, startIndex + 4) - startIndex += 4 - - buffer = buffer.subarray(startIndex, startIndex + payloadLength) - - for (let i = 0; i < buffer.length; i++) { - buffer[i] ^= mask[i & 3]; - } - } else { - buffer = buffer.subarray(startIndex, startIndex + payloadLength) - } + buffer = buffer.subarray(startIndex, startIndex + payloadLength) return { opcode, @@ -238,12 +224,6 @@ class WebSocket extends EventEmitter { return true } - send(data) { - const payload = Buffer.from(data, 'utf-8') - - return this.sendData(payload, { len: payload.length, fin: true, opcode: 0x01, mask: true }) - } - close(code, reason) { const data = Buffer.allocUnsafe(2 + Buffer.byteLength(reason || 'normal close')) data.writeUInt16BE(code || 1000)