MCPcopy Create free account
hub / github.com/vercel/vercel / _read_ws_frame

Function _read_ws_frame

python/vercel-runtime/tests/test_runtime.py:290–309  ·  view source on GitHub ↗
(reader: _SocketBuffer)

Source from the content-addressed store, hash-verified

288
289
290def _read_ws_frame(reader: _SocketBuffer) -> tuple[int, bytes]:
291 first, second = reader.read_exact(2)
292 opcode = first & 0x0F
293 payload_length = second & 0x7F
294 has_mask = bool(second & 0x80)
295
296 if payload_length == 126:
297 payload_length = struct.unpack("!H", reader.read_exact(2))[0]
298 elif payload_length == 127:
299 payload_length = struct.unpack("!Q", reader.read_exact(8))[0]
300
301 mask = reader.read_exact(4) if has_mask else b""
302 payload = reader.read_exact(payload_length) if payload_length else b""
303
304 if has_mask:
305 payload = bytes(
306 byte ^ mask[index % 4] for index, byte in enumerate(payload)
307 )
308
309 return opcode, payload
310
311
312def _build_websocket_request(

Callers 2

read_textMethod · 0.85
closeMethod · 0.85

Calls 1

read_exactMethod · 0.80

Tested by

no test coverage detected