IO-agnostic WebSocket frame parser and serializer in Zig. Zero allocations, no IO, bring-your-own-buffers. Implements RFC 6455.
src/root.zig— library entry point. Exports theclientandservernamespaces.src/client.zig— client namespace. Re-exports client-side types (Parser,FrameHandler,MessageWriter) and provides maskedwriteFrame/writeClose/writePing/writePong.src/server.zig— server namespace. Re-exports server-side types (Parser,FrameHandler,MessageWriter,UpgradeResponse) and provides unmaskedwriteFrame/writeClose/writePing/writePong.src/frame.zig— core types (Opcode,RsvBits,FrameHeader,Mask,Event,ParseError,WriteFrameOptions),BoundedBuffer,generateMaskKey, andreadInt/writeInthelpers.src/parse.zig— streamingParser(server/client),MessageValidator, andFrameHandler(higher-level message-oriented API).src/close.zig—CloseCode,ClosePayload,parseClosePayload.src/handshake.zig—computeAcceptKey,UpgradeRequest,validateUpgradeRequest,UpgradeResponse.src/message_writer.zig—MessageWriter(comptime masked: bool)generic, instantiated asServerMessageWriter(unmasked) andClientMessageWriter(masked).test/echo_server.zig— test scaffolding only. A minimal echo server for running the Autobahn conformance suite. Not part of the library.test/echo_client.zig— test scaffolding only. A minimal echo client for running the Autobahn client conformance suite against a fuzzingserver. Supports permessage-deflate. Not part of the library.examples/blocking-echo.zig— single-threaded blocking echo server usingstd.netandstd.Io. Simplest possible integration.examples/blocking-client.zig— single-threaded blocking WebSocket client usingstd.netandstd.Io. Pairs withblocking-echofor a complete client/server demo.examples/http-upgrade.zig— thread-per-connection HTTP server usingstd.http.Serverwith WebSocket upgrade on/wsand a static HTML page on/. Uses@embedFilefor the HTML.examples/xev-echo.zig— completion-based echo server using libxev's event loop with connection pooling. Most production-like example.
- No UTF-8 validation. Text frame payloads are treated as opaque bytes. UTF-8 validation is the caller's responsibility. The echo server does its own validation to satisfy Autobahn.
- Permessage-deflate. The library supports the
permessage-deflateextension (RFC 7692) via theExtensiontype and thecompressedflag onWriteFrameOptions. The echo server negotiates compression for the Autobahn conformance suite. - No handshake HTTP parsing. The library provides
computeAcceptKeyfor theSec-WebSocket-Acceptheader, but HTTP upgrade parsing is the caller's responsibility.
Requires Nix with flakes. All tools come from the devshell — do not install anything globally.
nix develop
All tasks are in the justfile:
just test # Run unit tests
just fmt # Format all Zig source files
just fmt-check # Check formatting without modifying files
just lint # Run ziglint
just check # Format check and lint
just examples # Build all examples
just autobahn-setup # Install the native Autobahn TestSuite runtime
just conformance # Run the fast native Autobahn suite for local iteration
just conformance-full # Run the full native Autobahn suite
just conformance-client # Run the fast Autobahn client conformance suite
just conformance-client-full # Run the full Autobahn client conformance suite
just conformance-xev # Run the fast Autobahn suite against xev echo server
just ci # All checks: format, lint, test, full conformance
just report # Serve the Autobahn HTML report on localhost:8080
The full RFC 6455 text is at rfc6455.txt in the project root. A quick-reference skill is at .agents/skills/rfc6455.md.