package cohttp

  1. Overview
  2. Docs

HTTP/1.1 response handling

This contains the metadata for a HTTP/1.1 response header, including the encoding, headers, version, status code and whether to flush the connection after every body chunk (useful for server-side events and other long-lived connection protocols). The body is handled by the separate S module type, as it is dependent on the IO implementation.

The interface exposes a fieldslib interface which provides individual accessor functions for each of the records below. It also provides sexp serializers to convert to-and-from an Core.Std.Sexp.t.

include S.Response
type t = {
  1. encoding : Transfer.encoding;
    (*

    Transfer encoding of this HTTP response

    *)
  2. headers : Header.t;
    (*

    response HTTP headers

    *)
  3. version : Code.version;
    (*

    (** HTTP version, usually 1.1 *)

    *)
  4. status : Code.status_code;
    (*

    HTTP status code of the response

    *)
  5. flush : bool;
}
include Sexplib0.Sexpable.S with type t := t
val t_of_sexp : Sexplib0__.Sexp.t -> t
val sexp_of_t : t -> Sexplib0__.Sexp.t
val encoding : t -> Transfer.encoding
val headers : t -> Header.t
val version : t -> Code.version
val status : t -> Code.status_code
val flush : t -> bool
val compare : t -> t -> int
val make : ?version:Code.version -> ?status:Code.status_code -> ?flush:bool -> ?encoding:Transfer.encoding -> ?headers:Header.t -> unit -> t

The response creates by make ~encoding ~headers () has an encoding value determined from the content of headers or if no proper header is present, using the value of encoding. Checked headers are "content-length", "content-range" and "transfer-encoding". The default value of encoding is chunked.

val pp_hum : Stdlib.Format.formatter -> t -> unit

Human-readable output, used by the toplevel printer

module Make (IO : S.IO) : S.Http_io with type t = t and module IO = IO

Functor to construct the IO-specific response handling function

OCaml

Innovation. Community. Security.