The client, relay, and gateway of Ohttp.Service, as calls and server callbacks of cohttp-lwt. The client, the relay, and the forwarding to targets make requests of their own, with any client of cohttp-lwt: that of cohttp-lwt-unix, or of cohttp-lwt-jsoo, or of a MirageOS unikernel.
module Ohttp_client = Ohttp_cohttp_lwt.Make (Cohttp_lwt_unix.Client)
(* A gateway for one target, over cohttp-lwt-unix. Build each handler once:
the requests in flight are counted in [service]. *)
let gateway =
Ohttp_cohttp_lwt.Gateway.handler service
(Ohttp_client.Target.forward
~targets:[ ("example.com", Uri.of_string "https://example.com") ])
let () =
Lwt_main.run
(Cohttp_lwt_unix.Server.create
(Cohttp_lwt_unix.Server.make ~callback:(fun _conn -> gateway) ()))
Contents are read in full: an encapsulated message is only opened when it is complete. Each read is limited (see Ohttp.Service.default_max_request_size and Ohttp.Service.default_max_response_size): what is longer is refused as soon as its declared length or what has arrived of it passes the limit, and the rest of it is read without being kept, since cohttp-lwt frees a connection only once its body has been read.
How a gateway gets a response for a request that it has decapsulated: from a target, with Make.Target.forward, from an application in the same process, with Target.of_handler, or in any other way.