bhttp

bhttp is a codec for the binary representation of HTTP messages (RFC 9292): requests and responses in both framings, with informational responses, trailers, padding, and truncation. It has no dependencies and performs no I/O.

The library is unaudited and not production-ready. It is intended for interoperability review.

Entry points

A message is a record of strings and of pairs of strings, which the types of any HTTP library convert to and from in a few lines:

  let request =
    Bhttp.Request.make ~meth:"GET" ~authority:"example.com" ~path:"/" ()
  in
  match Bhttp.Request.encode request with
  | Ok encoded -> Bhttp.Request.decode encoded = Ok request
  | Error e -> failwith (Bhttp.Error.to_string e)

Bhttp.Request and Bhttp.Response encode and decode one kind of message, and Bhttp.Message either kind. Decoding accepts what RFC 9292 allows an encoder to vary (the size of an integer, missing empty sections at the end, zero padding) and rejects what it makes invalid; field names come back in lowercase. Encoding refuses what decoding would reject.

Modules

Guides