h2 is an implementation of the
HTTP/2 specification entirely in OCaml.
It is based on the concepts in
http/af, and therefore uses the
Angstrom and Faraday libraries to implement the parsing
and serialization layers of the HTTP/2 standard. It also preserves the same API
as http/af wherever possible.
Install the library and its dependencies via OPAM:
opam install h2
There's generated documentation here
Examples TBD, see the
One of h2's goals is to be 100% compliant with the HTTP/2 specification.
There are currently 3 mechanisms in place to verify such conformance:
Unit tests using the HPACK stories in the
Unit tests using the test cases provided by the
Automated test runs (in CI) using the
h2spec conformance testing tool for
These test all the
Reqd.respond_with_*functions for conformance against
h2 aims to be a high-performance, memory-efficient, scalable, and easily
portable (with respect to different I/O runtimes) implementation. To achieve
that, it takes advantage of the unbuffered parsing interface in Angstrom using
off-heap buffers wherever possible, for both parsing and serialization.
h2 only currently provides a server implementation. In the future, a
client library will also be provided.
This source distribution provides a number of packages and examples. The
directory structure is as follows:
examples/: contains example applications using the various
I/O runtimes provided in this source distribution.
lib/: contains the core implementation of this library, including
HTTP/2 frame parsing, serialization and state machine implementations.
lib_test/: contains various unit tests for modules in the
core h2 package.
lwt/: contains an implementation of a Lwt runtime for h2
functorized over the specific input / output channel abstraction such that it
can work in either UNIX-like systems or MirageOS.
lwt-unix/: contains an Lwt runtime adapter for h2 that
communicates over UNIX file descriptors.
mirage/: contains a Mirage runtime adapter for h2 that
allows using h2 to write unikernels that serve traffic over HTTP/2.
Cloning the repository
# Use --recurse-submodules to get the test git submodules $ git clone email@example.com:anmonteiro/ocaml-h2.git --recurse-submodules
To install development dependencies, pin the package from the root of the
$ opam pin add -n hpack . $ opam pin add -n h2 . $ opam install --deps-only h2
After this, you may install a development version of the library using the
install command as usual.
Tests can be run via dune:
esy.json file at the root of this repository that can be used
to develop h2 with Esy.
To resolve and install the necessary dependencies, run:
Build any examples or run the tests by prefixing the
dune commands with
esy b or
esy build. For example:
$ esy b dune runtest
h2 is distributed under the 3-Clause BSD License, see LICENSE.