Guide
The protocol modules
The protocol modules
Whiplash's protocol code is sans-IO: each module takes bytes and returns events and bytes to send, and never touches a socket, a timer or a process. They can be used without the server, for a client, a proxy or a test.
| Module | Role |
|---|---|
whiplash/http1 |
Requests and, with http1.expect, responses; HTTP/1 serialisation |
whiplash/hpack, whiplash/hpack/fields |
HPACK coding and the field rules of HTTP/2 and HTTP/3 |
whiplash/http2 |
HTTP/2 frames and a server connection |
whiplash/websocket |
Frames, messages, handshakes, permessage-deflate; client and server |
whiplash/quic, whiplash/quic/connection, whiplash/quic/tls, whiplash/quic/crypto |
QUIC frames, a server connection, TLS 1.3, packet protection |
whiplash/qpack, whiplash/http3 |
QPACK and an HTTP/3 server connection |
HTTP/1
module main
import whiplash/http1
main() {
let parser = http1.requests(http1.default_limits())
let assert Ok(#(events, parser)) = http1.feed(
parser,
<<"GET /hello HTTP/1.1\r\nHost: example.com\r\n\r\n":utf8>>
)
echo events
let assert Ok([]) = http1.finish(parser)
}
Feed each read to the parser; events come in order (heads, body slices,
trailers, message ends) and one feed may finish several pipelined messages.
Body slices follow the input's fragmentation: compare joined bodies, not
slices. The parser refuses framing ambiguities (a transfer coding beside a
length, conflicting lengths, lengths beyond 63 bits, bare line feeds) and is
checked against llhttp's strict request and response suites, with the
differences listed in test/llhttp.spec.pooka. checked_response_head
validates a status and fields from application values; chunk and
last_chunk write chunked bodies.
WebSocket
websocket.reader(role, max_message) and websocket.writer(role, deflate)
are pure state: reading or writing returns a new reader or writer, and an
earlier one is never changed, compression dictionaries included. A server's
reader requires masked frames and a client's refuses them. Fragmentation,
interleaved control frames, incremental UTF-8 checks, close codes and limits
are handled before payloads are buffered. Decompression is bounded.
HTTP/2, QUIC and HTTP/3
http2.server(settings), quic.accept(datagram, identity, now) and
http3.server() start server connections; receive takes bytes and returns
events and bytes to send; flush, on_timeout and next_timeout drive the
rest. They implement the server side only.