Module Ocsigen.Response

type t
module Body : sig ... end
val make : ?body:Body.t -> ?cookies:Ocsigen_cookie_map.t -> Cohttp.Response.t -> t

Make a response from a Cohttp.Response.t. Note that the transfer-encoding header is not taken into account if it is set to chunked, use add_header. This is because Cohttp.Response.make sets this header by default, which interferes with the transfer-encoding carried by the body.

val respond : ?headers:Cohttp.Header.t -> status:Http.Status.t -> ?body:Body.t -> unit -> t

Like make but with an interface similar to Cohttp_lwt_unix.Server.respond.

val respond_string : ?headers:Cohttp.Header.t -> status:Http.Status.t -> body:string -> unit -> t

Like respond but with a fixed string body.

val respond_error : ?headers:Cohttp.Header.t -> ?status:Http.Status.t -> body:string -> unit -> t

Like respond_string with "Error: " appended to the body. The default status is `Internal_server_error.

  • deprecated

    Use respond_string with a ~status argument instead.

val respond_file : ?headers:Cohttp.Header.t -> ?status:Http.Status.t -> ?if_none_match:string -> ?if_modified_since:string -> ?range:string -> ?if_range:string -> string -> t Lwt.t

Respond with the content of a file. The content type is guessed using Magic_mime. An ETag (weak, derived from the file's modification time and size), a Last-Modified and an Accept-Ranges: bytes header are added. If the request's If-None-Match or If-Modified-Since header is passed and matches, the response is 304 Not Modified with an empty body (RFC 7232). If a range (the Range header) is passed and satisfiable, a single byte range is returned as 206 Partial Content with a Content-Range header (RFC 7233); an unsatisfiable range gives 416. A passed if_range (the If-Range header) must match the current validators for the range to be honoured.

val update : ?response:Cohttp.Response.t -> ?body:Body.t -> ?cookies:Ocsigen_cookie_map.t -> t -> t
val of_cohttp : ?cookies:Ocsigen_cookie_map.t -> (Cohttp.Response.t * Cohttp_lwt.Body.t) -> t
val to_response_expert : t -> Cohttp.Response.t * ('ic -> Lwt_io.output_channel -> unit Lwt.t)

Response for Cohttp_lwt_unix.Server.make_expert. Set cookie headers.

val response : t -> Cohttp.Response.t

Raw response without cookie headers set.

val body : t -> Body.t
val status : t -> Cohttp.Code.status
val set_status : t -> Cohttp.Code.status -> t
val cookies : t -> Ocsigen_cookie_map.t
val add_cookies : t -> Ocsigen_cookie_map.t -> t
val header : t -> Ocsigen_http.Header.Name.t -> string option
val header_multi : t -> Ocsigen_http.Header.Name.t -> string list
val add_header : t -> Ocsigen_http.Header.Name.t -> string -> t
val add_header_multi : t -> Ocsigen_http.Header.Name.t -> string list -> t
val replace_header : t -> Ocsigen_http.Header.Name.t -> string -> t
val replace_headers : t -> (Ocsigen_http.Header.Name.t * string) list -> t
val remove_header : t -> Ocsigen_http.Header.Name.t -> t