package ohttp-cohttp-lwt

  1. Overview
  2. Docs

Module Ohttp_cohttp_lwtSource

Oblivious HTTP over cohttp-lwt.

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.

The callback of a cohttp-lwt server, without its connection: Cohttp_lwt_unix.Server.make ~callback:(fun _conn -> handler) ().

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.

Sourcemodule Gateway : sig ... end

A gateway: its key configurations, and the resource to which relays send Encapsulated Requests.

Sourcemodule Target : sig ... end

Targets that live in the same process as the gateway.

Sourcemodule Make (Http_client : Cohttp_lwt.S.Client) : sig ... end