package cohttp

  1. Overview
  2. Docs

Source file server.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
module type S = sig
  module IO : S.IO

  type body
  type conn = IO.conn * Connection.t [@@warning "-3"]
  type response

  type response_action =
    [ `Expert of Http.Response.t * (IO.ic -> IO.oc -> unit IO.t)
    | `Response of response ]
  (** A request handler can respond in two ways:

      - Using [`Response], with a {!Response.t} and a {!body}.
      - Using [`Expert], with a {!Response.t} and an IO function that is
        expected to write the response body. The IO function has access to the
        underlying {!IO.ic} and {!IO.oc}, which allows writing a response body
        more efficiently, stream a response or to switch protocols entirely
        (e.g. websockets). Processing of pipelined requests continue after the
        [unit IO.t] is resolved. The connection can be closed by closing the
        {!IO.ic}. *)

  type t

  val make_response_action :
    ?conn_closed:(conn -> unit) ->
    callback:(conn -> Http.Request.t -> body -> response_action IO.t) ->
    unit ->
    t

  val make_expert :
    ?conn_closed:(conn -> unit) ->
    callback:
      (conn ->
      Http.Request.t ->
      body ->
      (Http.Response.t * (IO.ic -> IO.oc -> unit IO.t)) IO.t) ->
    unit ->
    t

  val make :
    ?conn_closed:(conn -> unit) ->
    callback:(conn -> Http.Request.t -> body -> response IO.t) ->
    unit ->
    t

  val respond :
    ?headers:Http.Header.t ->
    status:Http.Status.t ->
    body:body ->
    unit ->
    response IO.t
  (** [respond ?headers ~status ~body] will respond to an HTTP request with the
      given [status] code and response [body]. The transfer encoding will be
      detected from the [body] value and set to chunked encoding if it cannot be
      determined immediately. You can override the encoding by supplying an
      appropriate [Content-length] or [Transfer-encoding] in the [headers]
      parameter. *)

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

  val callback : t -> IO.conn -> IO.ic -> IO.oc -> unit IO.t
end
OCaml

Innovation. Community. Security.