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
open Http_core
module OpiumResponse = struct
type t = Opium_kernel.Response.t
let equal _ _ = false
let pp _ _ = ()
end
type body =
| String of string
| File_path of string
[@@deriving show, eq]
type t =
{ content_type : content_type
; redirect : string option
; body : body option
; headers : headers
;
opium_res : OpiumResponse.t option
; cookies : (string * string) list
; status : int
}
[@@deriving show, eq]
let file path content_type =
{ content_type
; redirect = None
; body = Some (File_path path)
; headers = []
; opium_res = None
; cookies = []
; status = 200
}
;;
let html =
{ content_type = Html
; redirect = None
; body = None
; headers = []
; opium_res = None
; cookies = []
; status = 200
}
;;
let json =
{ content_type = Json
; redirect = None
; body = None
; headers = []
; opium_res = None
; cookies = []
; status = 200
}
;;
let redirect path =
{ content_type = Html
; redirect = Some path
; body = None
; headers = []
; opium_res = None
; cookies = []
; status = 302
}
;;
let redirect_path res = res.redirect
let body res = res.body
let set_body str res = { res with body = Some (String str) }
let res = res.headers
let res = { res with headers }
let content_type res = res.content_type
let set_content_type content_type res = { res with content_type }
let opium_res res = res.opium_res
let set_opium_res opium_res res = { res with opium_res = Some opium_res }
let cookies res = res.cookies
let set_cookie ~key ~data res = { res with cookies = List.cons (key, data) res.cookies }
let status res = res.status
let set_status status res = { res with status }