http_websocket_frames
This library provides the transport-neutral WebSocket helpers shared by
the current HTTP stack. It includes normalized frame terms and binary
frame parsing and generation in the http_websocket_frames object.
API documentation
Open the ../../apis/library_index.html#http_websocket_frames link in a web browser.
Loading
To load the full library, load the loader.lgt file:
| ?- logtalk_load(http_websocket_frames(loader)).
Testing
To test this library, load the tester.lgt file:
| ?- logtalk_load(http_websocket_frames(tester)).
Current scope
The current implementation provides:
frame/5for constructing validated normalized WebSocket frame terms.is_frame/1for testing normalized frame terms.final/2,opcode/2,payload/2,properties/2, andproperty/2for inspecting normalized frame terms.parse/2andgenerate/2for binary source and sink terms.read_frame/2andwrite_frame/2for incremental frame I/O on binary streams.
Normalized terms
Frames use the normalized term:
frame(Final, Opcode, Payload, Properties)
Where:
Finalis eitherfinalormore.Opcodeis one ofcontinuation,text,binary,close,ping, orpong.Payloadis a list of bytes.Propertiescurrently recognizes:masking_key(Key)whereKeyis a four-byte list.reserved_bits(Bits)whereBitsis an ordered subset of[rsv1, rsv2, rsv3].
Valid properties
The Properties list accepted by frame/5, generate/2, and
write_frame/2 can contain only the following properties:
masking_key(Key)Keymust be a list of exactly four bytes.Each byte must be an integer in the
0..255range.
reserved_bits(Bits)Bitsmust be a list containing any ordered subset of[rsv1, rsv2, rsv3].Duplicate reserved-bit atoms are invalid.
Each property can be given at most once. When both properties are
present, the normalized property list is returned in the canonical order
[reserved_bits(Bits), masking_key(Key)].
Current workflow
Use
read_frame/2andwrite_frame/2on those streams to exchange WebSocket frames.Use the higher-level
http_websocket_messageslibrary when you need continuation reassembly or UTF-8-aware text and close-reason handling.Use the
http_websocket_sessionlibrary when fragmented reads must preserve pending state across interleaved control frames or when outgoing writes should apply client or server masking policy automatically.Use
parse/2andgenerate/2when working with in-memory byte lists or binary files instead of live streams.
Current limitations
This library operates at the frame level only. It does not provide application session loops.
This layer does not provide message reassembly or UTF-8-aware text and close-reason handling.
Client and server masking policy is not enforced by role in this frame layer. The presence of a
masking_key/1property controls whether outgoing frames are masked. Use thehttp_websocket_sessionlayer when you want role-aware writes and role-aware incoming masking validation.Reserved bits are preserved structurally but no extension negotiation or extension semantics are implemented.