···11-(** WebSocket frame codec (RFC 6455).
11+(** WebSocket protocol (RFC 6455).
22+33+ This module exposes both layers of RFC 6455:
44+55+ - The frame codec at the top of the module — encode/decode frames,
66+ masking, fragmentation, ping/pong, close.
77+ - The HTTP upgrade handshake under {!module:Handshake} — Sec-WebSocket-Key
88+ generation, Sec-WebSocket-Accept computation, protocol/extension
99+ negotiation, request/response header builders.
21033- Encode and decode WebSocket frames. Handles masking, fragmentation,
44- ping/pong, and close frames. Does NOT handle the HTTP upgrade handshake —
55- see [ocaml-requests] for that.
1111+ Use {!module:Handshake} to upgrade an HTTP/1.1 connection to a WebSocket;
1212+ once upgraded, switch to {!encode}/{!decode} to drive the wire protocol.
613714 {[
88- let frame = Frame.text "hello" in
99- let bytes = Frame.encode frame in
1010- match Frame.decode bytes with
1111- | Ok (frame, rest) -> ...
1212- | Error `Need_more -> (* incomplete frame *)
1515+ let frame = Websocket.text "hello"
1616+ let bytes = Websocket.encode frame
1717+1818+ let () =
1919+ match Websocket.decode bytes with
2020+ | Ok (frame, _rest) -> assert (frame.payload = "hello")
2121+ | Error _ -> assert false
1322 ]} *)
2323+2424+module Handshake = Handshake
2525+(** RFC 6455 §4: HTTP upgrade handshake. *)
14261527(** {1 Opcode} *)
1628
+11-3
nox-websocket.opam
···11# This file is generated by dune, edit dune-project instead
22opam-version: "2.0"
33-synopsis: "WebSocket frame codec (RFC 6455)"
33+synopsis: "WebSocket protocol (RFC 6455): frame codec and HTTP handshake"
44description: """
55-Encode and decode WebSocket frames. Handles masking, fragmentation,
66-ping/pong, and close frames. Does not handle the HTTP upgrade handshake."""
55+Both layers of RFC 6455: the frame codec (encode/decode, masking,
66+fragmentation, ping/pong, close) at the top of the [Websocket] module,
77+and the HTTP upgrade handshake (Sec-WebSocket-Key generation,
88+Sec-WebSocket-Accept computation, protocol/extension negotiation)
99+under [Websocket.Handshake]."""
710maintainer: ["Thomas Gazagnaire <thomas@gazagnaire.org>"]
811authors: ["Thomas Gazagnaire <thomas@gazagnaire.org>"]
912license: "ISC"
···1417 "dune" {>= "3.21"}
1518 "ocaml" {>= "5.2"}
1619 "fmt" {>= "0.9"}
2020+ "logs"
2121+ "base64"
2222+ "digestif"
2323+ "nox-crypto-rng"
2424+ "nox-http"
1725 "alcotest" {with-test}
1826 "mdx" {with-test}
1927 "alcobar" {with-test}