-
Notifications
You must be signed in to change notification settings - Fork 176
/
s.ml
135 lines (113 loc) · 4.43 KB
/
s.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
(*{{{ Copyright (C) 2012-2014 Anil Madhavapeddy <[email protected]>
* Copyright (c) 2014 Rudi Grinberg
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
}}}*)
(** Module type signatures for Cohttp components *)
(** The [IO] module defines the blocking interface for reading
and writing to Cohttp streams *)
module type IO = sig
(** ['a t] represents a blocking monad state *)
type +'a t
(** [a >>= b] will pass the result of [a] to the
[b] function. This is a monadic [bind]. *)
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
(** [return a] will construct a constant IO value. *)
val return : 'a -> 'a t
(** [ic] represents an input channel *)
type ic
(** [oc] represents an output channel *)
type oc
(** [conn] represents the underlying network flow *)
type conn
(** [read_line ic] will read a single line terminated
by CR or CRLF from the input channel [ic]. It returns
{!None} if EOF or other error condition is reached. *)
val read_line : ic -> string option t
(** [read ic len] will block until a maximum of [len] characters
are read from the input channel [ic]. It returns an
empty string if EOF or some other error condition occurs
on the input channel, and can also return fewer than [len]
characters if input buffering is not sufficient to satisfy the
request. *)
val read : ic -> int -> string t
(** [write oc s] will block until the complete [s] string is
written to the output channel [oc]. *)
val write : oc -> string -> unit t
(** [flush oc] will return when all previously buffered content
from calling {!write} have been written to the output channel
[oc]. *)
val flush : oc -> unit t
end
module type Http_io = sig
type t
type reader
type writer
module IO : IO
val read : IO.ic -> [ `Eof | `Invalid of string | `Ok of t ] IO.t
val has_body : t -> [ `No | `Unknown | `Yes ]
val make_body_writer : ?flush:bool -> t -> IO.oc -> writer
val make_body_reader : t -> IO.ic -> reader
val read_body_chunk : reader -> Transfer.chunk IO.t
val write_header : t -> IO.oc -> unit IO.t
val write_body : writer -> string -> unit IO.t
val write : ?flush:bool -> (writer -> unit IO.t) -> t -> IO.oc -> unit IO.t
end
module type Request = sig
type t = {
headers: Header.t; (** HTTP request headers *)
meth: Code.meth; (** HTTP request method *)
resource: string; (** Request path and query *)
version: Code.version; (** HTTP version, usually 1.1 *)
encoding: Transfer.encoding; (** transfer encoding of this HTTP request *)
} [@@deriving fields, sexp]
val make : ?meth:Code.meth -> ?version:Code.version ->
?encoding:Transfer.encoding -> ?headers:Header.t ->
Uri.t -> t
(** Return true whether the connection should be reused *)
val is_keep_alive : t -> bool
val uri : t -> Uri.t
val make_for_client:
?headers:Header.t ->
?chunked:bool ->
?body_length:int64 ->
Code.meth -> Uri.t -> t
end
module type Response = sig
type t = {
encoding: Transfer.encoding; (** Transfer encoding of this HTTP response *)
headers: Header.t; (** response HTTP headers *)
version: Code.version; (** (** HTTP version, usually 1.1 *) *)
status: Code.status_code; (** HTTP status code of the response *)
flush: bool;
} [@@deriving fields, sexp]
val make :
?version:Code.version ->
?status:Code.status_code ->
?flush:bool ->
?encoding:Transfer.encoding ->
?headers:Header.t ->
unit -> t
end
module type Body = sig
type t
val to_string : t -> string
val to_string_list : t -> string list
val empty : t
val is_empty : t -> bool
val of_string : string -> t
val of_string_list : string list -> t
val map : (string -> string) -> t -> t
val transfer_encoding : t -> Transfer.encoding
end