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
include Awso_common.Jane_compat
open Lwt.Infix
let file_contents file =
let stream = Lwt_io.chars_of_file file in
Lwt_stream.to_string stream >>= fun contents -> Lwt.return contents
;;
module Cohttp : sig
module Body = Cohttp_lwt.Body
module Code = Cohttp.Code
module Client = Cohttp_lwt_unix.Client
module Request = Cohttp.Request
module Response = Cohttp.Response
val to_meth : Awso.Http.Meth.t -> Cohttp.Code.meth
val of_version : Cohttp.Response.t -> int * int
val of_status : Cohttp.Response.t -> Awso.Http.Status.t
end = struct
module Body = Cohttp_lwt.Body
module Code = Cohttp.Code
module Client = Cohttp_lwt_unix.Client
module Request = Cohttp.Request
module Response = Cohttp.Response
let to_meth meth = (meth :> Cohttp.Code.meth)
let req =
req |> Awso.Http.Request.headers |> Awso.Http.Headers.to_list |> Cohttp.Header.of_list
;;
let of_version resp =
match Cohttp.Response.version resp with
| `HTTP_1_0 -> 1, 0
| `HTTP_1_1 -> 1, 1
| `Other _ ->
0, 0
;;
let resp =
resp |> Cohttp.Response.headers |> Cohttp.Header.to_list |> Awso.Http.Headers.of_list
;;
let of_status resp =
match Cohttp.Response.status resp with
| #Awso.Http.Status.t as status -> (status :> Awso.Http.Status.t)
| status -> `Code (Cohttp.Code.code_of_status status)
;;
end
module Cohttp_async = struct end