MCPcopy Create free account
hub / github.com/angular/dev-infra / parseControlFrame

Method parseControlFrame

github-actions/browserstack/set-browserstack-env.js:18078–18129  ·  view source on GitHub ↗

* Parses control frames. * @param {Buffer} body

(body)

Source from the content-addressed store, hash-verified

18076 if (!isValidOpcode(opcode)) {
18077 failWebsocketConnection(this.ws, "Invalid opcode received");
18078 return callback();
18079 }
18080 if (masked) {
18081 failWebsocketConnection(this.ws, "Frame cannot be masked");
18082 return callback();
18083 }
18084 if (rsv1 !== 0 && !__privateGet(this, _extensions).has("permessage-deflate")) {
18085 failWebsocketConnection(this.ws, "Expected RSV1 to be clear.");
18086 return;
18087 }
18088 if (rsv2 !== 0 || rsv3 !== 0) {
18089 failWebsocketConnection(this.ws, "RSV1, RSV2, RSV3 must be clear");
18090 return;
18091 }
18092 if (fragmented && !isTextBinaryFrame(opcode)) {
18093 failWebsocketConnection(this.ws, "Invalid frame type was fragmented.");
18094 return;
18095 }
18096 if (isTextBinaryFrame(opcode) && __privateGet(this, _fragments).length > 0) {
18097 failWebsocketConnection(this.ws, "Expected continuation frame");
18098 return;
18099 }
18100 if (__privateGet(this, _info).fragmented && fragmented) {
18101 failWebsocketConnection(this.ws, "Fragmented frame exceeded 125 bytes.");
18102 return;
18103 }
18104 if ((payloadLength > 125 || fragmented) && isControlFrame(opcode)) {
18105 failWebsocketConnection(this.ws, "Control frame either too large or fragmented");
18106 return;
18107 }
18108 if (isContinuationFrame(opcode) && __privateGet(this, _fragments).length === 0 && !__privateGet(this, _info).compressed) {
18109 failWebsocketConnection(this.ws, "Unexpected continuation frame");
18110 return;
18111 }
18112 if (payloadLength <= 125) {
18113 __privateGet(this, _info).payloadLength = payloadLength;
18114 __privateSet(this, _state, parserStates.READ_DATA);
18115 if (!__privateMethod(this, _validatePayloadLength, validatePayloadLength_fn).call(this)) {
18116 return;
18117 }
18118 } else if (payloadLength === 126) {
18119 __privateSet(this, _state, parserStates.PAYLOADLENGTH_16);
18120 } else if (payloadLength === 127) {
18121 __privateSet(this, _state, parserStates.PAYLOADLENGTH_64);
18122 }
18123 if (isTextBinaryFrame(opcode)) {
18124 __privateGet(this, _info).binaryType = opcode;
18125 __privateGet(this, _info).compressed = rsv1 !== 0;
18126 }
18127 __privateGet(this, _info).opcode = opcode;
18128 __privateGet(this, _info).masked = masked;
18129 __privateGet(this, _info).fin = fin;
18130 __privateGet(this, _info).fragmented = fragmented;
18131 } else if (__privateGet(this, _state) === parserStates.PAYLOADLENGTH_16) {
18132 if (__privateGet(this, _byteOffset) < 2) {

Callers 1

runMethod · 0.45

Calls 6

__privateGetFunction · 0.70
failWebsocketConnectionFunction · 0.70
closeWebSocketConnectionFunction · 0.70
parseCloseBodyMethod · 0.45
writeMethod · 0.45
createFrameMethod · 0.45

Tested by

no test coverage detected