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§
- Frame
Decoder - The frame decoder for one connection.
- Handshake
- A valid opening handshake.
- WsLimits
- Size limits.
Enums§
- Handshake
Error - 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
426reply for an unsupportedSec-WebSocket-Version.
Functions§
- accept_
key Sec-WebSocket-Acceptfor aSec-WebSocket-Key.- apply_
mask - XORs
datawith the maskkey, starting at byteoffsetof the key stream. - encode_
header - Writes a frame header into
out; returns its length (2 to 14 bytes). Clients must pass a fresh randommaskper frame and mask the payload withapply_mask; servers passNone. - validate_
handshake - Checks a request against RFC 6455 §4.2.1.
- validate_
response - Client side: true if
respaccepts the handshake started withkey. - write_
accept - Appends the
101reply, choosingprotocol(which must be one the client offered). - write_
accept_ with write_acceptwith aSec-WebSocket-Extensionsvalue (from [deflate::negotiate]).- write_
close - Appends a Close frame;
reasonmust fit (at most 123 bytes) andcodemust be sendable. - write_
frame - Appends a whole frame (masked when
maskis given). - write_
frame_ compressed write_framefor a compressed (permessage-deflate) message: RSV1 set on this, its first frame.