The client, relay, and gateway of Ohttp.Service, as calls and server handlers of Piaf, over HTTP/1.1 or HTTP/2.
Eio_main.run @@ fun env ->
Eio.Switch.run @@ fun sw ->
(* A gateway for one target. Build each handler once: the requests in flight
are counted in [service]. *)
let gateway =
Ohttp_piaf.Gateway.handler service
(Ohttp_piaf.Target.forward env
~targets:[ ("example.com", Uri.of_string "http://127.0.0.1:8000") ])
in
let config =
Piaf.Server.Config.create (`Tcp (Eio.Net.Ipaddr.V4.any, 8080))
in
ignore
(Piaf.Server.Command.start ~sw env (Piaf.Server.create ~config 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 Piaf is done with a message only once its body has been read. Every request that the client, the relay, or the forwarding to a target makes is a Piaf.Client.Oneshot request, in a switch of its own that it leaves when the response has been read.