MCPcopy
hub / github.com/benoitc/gunicorn / _send_frame

Method _send_frame

gunicorn/asgi/websocket.py:394–421  ·  view source on GitHub ↗

Send a WebSocket frame. Server frames are not masked (RFC 6455).

(self, opcode, payload)

Source from the content-addressed store, hash-verified

392 # This is called for partial fragments, nothing to do here
393
394 async def _send_frame(self, opcode, payload):
395 """Send a WebSocket frame.
396
397 Server frames are not masked (RFC 6455).
398 """
399 if isinstance(payload, str):
400 payload = payload.encode("utf-8")
401
402 length = len(payload)
403 frame = bytearray()
404
405 # First byte: FIN + opcode
406 frame.append(0x80 | opcode)
407
408 # Second byte: length (no mask bit for server)
409 if length < 126:
410 frame.append(length)
411 elif length < 65536:
412 frame.append(126)
413 frame.extend(struct.pack("!H", length))
414 else:
415 frame.append(127)
416 frame.extend(struct.pack("!Q", length))
417
418 # Payload
419 frame.extend(payload)
420
421 self.transport.write(bytes(frame))
422
423 async def _send_close(self, code, reason=""):
424 """Send a close frame."""

Callers 3

_sendMethod · 0.95
_read_framesMethod · 0.95
_send_closeMethod · 0.95

Calls 2

encodeMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected