package cohttp-lwt

  1. Overview
  2. Docs

Portable Lwt implementation of HTTP client and server, without depending on a particular I/O implementation. The various Make functors must be instantiated by an implementation that provides a concrete IO monad.

module type IO = sig ... end

The IO module is specialized for the Lwt monad.

module type Net = sig ... end

The Net module type defines how to connect to a remote node and close the resulting channels to clean up.

module type Sleep = sig ... end

This is compatible with Mirage_time.S. It may be satisfied by mirage-time-unix Time or Mirage_time.

type call = ?headers:Http.Header.t -> ?body:Body.t -> Http.Method.t -> Uri.t -> (Cohttp.Response.t * Body.t) Lwt.t

call ?headers ?body method uri Function type used to handle http requests

  • returns

    (response, response_body) response_body is not buffered, but stays on the wire until consumed. It must therefore be consumed in a timely manner. Otherwise the connection would stay open and a file descriptor leak may be caused. Following responses would get blocked. Functions in the Body module can be used to consume response_body. Use Body.drain_body if you don't consume the body by other means.

    Leaks are detected by the GC and logged as debug messages, these can be enabled activating the debug logging. For example, this can be done as follows in cohttp-lwt-unix

    Cohttp_lwt_unix.Debug.activate_debug ();
    Logs.set_level (Some Logs.Warning)
  • raises {!exception

    Connection.Retry

}

on recoverable errors like the remote endpoint closing the connection gracefully. Even non-idempotent requests are guaranteed to not have been processed by the remote endpoint and should be retried. But beware that a `Stream body may have been consumed.

module type Connection = sig ... end

The Connection module handles a single, possibly pipelined, http connection.

module type Connection_cache = sig ... end

A Connection_cache handles http requests. It not necessarily caches connections.

module type Client = sig ... end

The Client module is a collection of convenience functions for constructing and processing requests.

module type Server = sig ... end

The Server module implements a pipelined HTTP/1.1 server.

OCaml

Innovation. Community. Security.