package piaf

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file http_intf.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
(*----------------------------------------------------------------------------
 * Copyright (c) 2019-2020, António Nuno Monteiro
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived from
 *    this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *---------------------------------------------------------------------------*)

type error_handler = kind:Error.kind -> Error.client -> unit
type response_handler = Response.t -> unit

module type Client = sig
  type t
  type write_body

  val create_connection :
     config:Config.t
    -> error_handler:error_handler
    -> sw:Eio.Switch.t
    -> Eio_unix.Net.stream_socket_ty Eio.Net.stream_socket
    -> t * Gluten_eio.Client.t

  val request :
     t
    -> flush_headers_immediately:bool
    -> error_handler:error_handler
    -> response_handler:response_handler
    -> Request.t
    -> write_body

  val shutdown : t -> unit Eio.Promise.t
  val is_closed : t -> bool
end

module type Reqd = sig
  type write_body
  type t

  val respond_with_string : t -> Response.t -> string -> unit
  val respond_with_bigstring : t -> Response.t -> Bigstringaf.t -> unit

  val respond_with_streaming :
     t
    -> ?flush_headers_immediately:bool
    -> Response.t
    -> write_body

  val respond_with_upgrade : t -> Headers.t -> (unit -> unit) -> unit

  val error_code :
     t
    -> [ `Bad_request | `Bad_gateway | `Internal_server_error | `Exn of exn ]
         option

  val report_exn : t -> exn -> unit
  val try_with : t -> (unit -> unit) -> (unit, exn) result
end

module type Server = sig
  type write_body

  module Reqd : Reqd with type write_body := write_body

  val create_connection_handler :
     config:Server_config.t
    -> request_handler:Request_info.t Server_intf.Handler.t
    -> error_handler:Server_intf.error_handler
    -> Server_intf.connection_handler
end

(* Common signature for sharing HTTP/1.X / HTTP/2 implementations. *)
module type HTTPCommon = sig
  type scheme

  val scheme : Scheme.t

  module Body : Body.Raw.BODY
  module Client : Client with type write_body := Body.Writer.t
  module Server : Server with type write_body := Body.Writer.t
end

module type HTTPServerCommon = sig
  module Body : Body.Raw.BODY
  module Reqd : Reqd with type write_body := Body.Writer.t
end

module type HTTP1 = sig
  type scheme

  val scheme : Scheme.t

  module Body : Body.Raw.BODY
  module Client : Client with type write_body := Body.Writer.t
  module Server : Server with type write_body := Body.Writer.t
end

module type HTTP = HTTPCommon with type scheme = Scheme.http
module type HTTPS = HTTPCommon with type scheme = Scheme.https

module Piaf_body = Body

(* Only needed for h2c upgrades (insecure HTTP/2) *)
module type HTTP2 = sig
    type scheme

    val scheme : Scheme.t

    module Body : Body.Raw.BODY

    module Client : sig
      include Client with type write_body := Body.Writer.t

      val create_h2c :
         config:Config.t
        -> ?push_handler:(Request.t -> (response_handler, unit) result)
        -> http_request:Httpun.Request.t
        -> error_handler:error_handler
        -> response_handler * error_handler
        -> Gluten_eio.Client.t
        -> (t, string) result
    end

    module Server : sig
      include Server with type write_body := Body.Writer.t

      val create_h2c_connection_handler :
         config:Server_config.t
        -> sw:Eio.Switch.t
        -> fd:Eio_unix.Net.stream_socket_ty Eio.Net.stream_socket
        -> error_handler:Server_intf.error_handler
        -> http_request:Httpun.Request.t
        -> request_body:Bigstringaf.t IOVec.t list
        -> client_address:Eio.Net.Sockaddr.stream
        -> Request_info.t Server_intf.Handler.t
        -> (H2.Server_connection.t, string) result
    end
  end
  with type Client.t = H2_eio.Client.t