High-performance HTTP parser achieving true zero heap allocations using OxCaml’s unboxed types and stack allocation. Parse at 6.5M requests/sec with RFC 7230 security compliance.
Create a simple parser that achieves zero allocations:
open Httpzlet parse_request socket_data = let buf = Httpz.create_buffer () in (* Read data into buffer *) let len = read_socket_into buf socket_data in (* Parse with zero heap allocations *) let #(status, req, headers) = Httpz.parse buf ~len ~limits:Httpz.default_limits in match status with | Buf_read.Complete -> (* All values are stack-allocated *) Printf.printf "Method: %s\n" (Method.to_string req.#meth); Printf.printf "Target: %s\n" (Span.to_string buf req.#target); List.iter (fun hdr -> Printf.printf "Header: %s\n" (Header_name.canonical hdr.Header.name) ) headers | _ -> Printf.eprintf "Parse failed\n"
The #(...) syntax creates an unboxed tuple, and req.#field accesses unboxed record fields. Everything stays on the stack!
4
Try the static file server
httpz includes a production-ready static file server:
# Serve current directory on port 8080dune exec bin/httpz_server.exe# Custom directory and portdune exec bin/httpz_server.exe -- -d /var/www -p 3000
The server handles 10,000 concurrent connections with zero-copy I/O and automatic MIME type detection.
Key features
Built for performance with OxCaml’s advanced type system
True zero allocations
Parser results are entirely stack-allocated using unboxed records and local lists. No GC pressure.
Unboxed types throughout
Uses int16#, int64#, and char# for offsets and lengths. No boxing overhead.
RFC 7230 security
Prevents request smuggling with bare CR detection and ambiguous framing checks.
Complete HTTP/1.1 support
Chunked encoding, ETags, range requests, keep-alive, and conditional requests.
6.5M requests/sec
Benchmarked at 154ns for minimal requests with 45x fewer allocations than alternatives.
Direct bigstring I/O
Read and write directly to bigarrays for zero-copy integration with Async.