package llhttp
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=15df5913f395a71207514087a3c4411390c157b4761a0434ccda973a83218f39
sha512=2a0e83254e19d1d0431886b3e302a7e78a9311bca54ea7595643d1ccf03654cd759050625585d5b4f2f5ba3de16d14cdda160da8e2bce2f010140e411706b51a
Description
OCaml bindings for llhttp
Published: 28 Jul 2025
README
OCaml bindings for llhttp
llhttp is a performant HTTP parser used in Node.js
Intents
This project prefers vendoring and static linking so that this library can be used more seamlessly within the OCaml ecosystem.
The current goal is to get more of the functionality implemented into this binding, but more focus on performance might be done later.
Bug reports
Feel free to open an issue with any information you have. Any help addressing the issue would be appreciated.
Contributing
Feel free to open a PR with any contributions you might have.
Example
let empty_data_cb name = fun data -> Printf.printf "Data callback %s with %s\n" name data; 0
let empty_cb name = fun () -> Printf.printf "No data callback %s\n" name; 0
let () =
let parser = Ocaml_llhttp.Llhttp.init HTTP_REQUEST in
let () = Ocaml_llhttp.Llhttp.callback parser "on_message_begin" @@ empty_cb "on_message_begin" in
let () = Ocaml_llhttp.Llhttp.data_callback parser "on_protocol" @@ empty_data_cb "on_protocol" in
let http_data = "GET /path HTTP/1.1\r\nHost: example.com\r\n\r\n" in
match Ocaml_llhttp.Llhttp.execute parser http_data with
| 0 -> print_endline "Parsing successful"
| code -> Printf.printf "Parsing failed with error code: %d\n" code
As you can see from this example, the binding is quite low level and is closely tied to llhttp with a few changes.
llhttp
This was forked from master of llhttp when the latest release was v9.3.0.
Updating llhttp
Assuming no changes to the interface, it is possible to plug in the latest version of llhttp using the following steps.
- Clone llhttp to a local directory
- Run
npm ci
followed bymake
from the llhttp directory Copy the following files into
lib/vend
of the ocaml-llhttp project- llhttp/build/c/llhttp.c
- llhttp/src/native/http.c
- llhttp/src/native/api.c
- llhttp/build/llhttp.h
Docs
Currently the only real documentation is found in lib/llhttp.mli, but it would be nice to have more formal documentation. Examples and a function level reference would be ideal.