This commit is contained in:
cod 2024-09-23 11:40:15 +02:00
parent 14875dba34
commit c268891bbf

View file

@ -71,7 +71,7 @@ class WebSocketDecode extends Operation {
throw new OperationError(`Expected size: ${(pos + payloadLength + maskSize)}`); throw new OperationError(`Expected size: ${(pos + payloadLength + maskSize)}`);
} }
let maskBytes = Buffer.alloc(4); const maskBytes = Buffer.alloc(4);
if (mask) { if (mask) {
maskBytes[0] = buf[pos]; maskBytes[0] = buf[pos];
@ -81,10 +81,10 @@ class WebSocketDecode extends Operation {
pos += 4; pos += 4;
} }
let payload = buf.slice(pos, buf.length); const payload = buf.slice(pos, buf.length);
if (mask) { if (mask) {
for(var i = 0; i < payload.length; i++) { for (let i = 0; i < payload.length; i++) {
payload[i] = payload[i] ^ maskBytes[i % 4]; payload[i] = payload[i] ^ maskBytes[i % 4];
} }
} }
@ -94,14 +94,14 @@ class WebSocketDecode extends Operation {
if ((b0 & 1) === 1) { if ((b0 & 1) === 1) {
content = payload.toString(); content = payload.toString();
} else { } else {
content = payload.toString('hex'); content = payload.toString("hex");
} }
const ws = { const ws = {
fin: fin, fin: fin,
opcode: opcode, opcode: opcode,
mask_present: mask, maskPresent: mask,
mask: maskBytes.toString('hex'), mask: maskBytes.toString("hex"),
payloadLength: payloadLength, payloadLength: payloadLength,
payload: content payload: content
}; };