Skip to main content

Module ws

Module ws 

Source
Expand description

WebSocket (RFC 6455): handshake validation and a sans-io frame codec.

The decoder unmasks in place and streams data-frame payloads as they arrive (no frame is buffered whole except control frames, at most 131 bytes). It checks reserved bits, opcodes, masking direction, minimal length encoding, control-frame rules, fragmentation order, close codes, UTF-8 of text messages across fragments, and frame and message size limits. Extensions: permessage-deflate (RFC 7692) with the permessage-deflate feature ([deflate]); without a negotiated extension the RSV bits must be zero.

Structs§

FrameDecoder
The frame decoder for one connection.
Handshake
A valid opening handshake.
WsLimits
Size limits.

Enums§

HandshakeError
Why an upgrade request is not a valid WebSocket opening handshake.
Opcode
Frame opcodes.
Role
Which end this codec is: a server expects masked frames, a client unmasked ones.
WsError
A protocol violation; the connection must be closed with WsError::close_code.
WsEvent
One decoded event.

Constants§

GUID
The GUID from RFC 6455 §1.3.
VERSION_REQUIRED
The 426 reply for an unsupported Sec-WebSocket-Version.

Functions§

accept_key
Sec-WebSocket-Accept for a Sec-WebSocket-Key.
apply_mask
XORs data with the mask key, starting at byte offset of the key stream.
encode_header
Writes a frame header into out; returns its length (2 to 14 bytes). Clients must pass a fresh random mask per frame and mask the payload with apply_mask; servers pass None.
validate_handshake
Checks a request against RFC 6455 §4.2.1.
validate_response
Client side: true if resp accepts the handshake started with key.
write_accept
Appends the 101 reply, choosing protocol (which must be one the client offered).
write_accept_with
write_accept with a Sec-WebSocket-Extensions value (from [deflate::negotiate]).
write_close
Appends a Close frame; reason must fit (at most 123 bytes) and code must be sendable.
write_frame
Appends a whole frame (masked when mask is given).
write_frame_compressed
write_frame for a compressed (permessage-deflate) message: RSV1 set on this, its first frame.