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
module Dream = Dream__pure.Inmost
let address_to_string : Unix.sockaddr -> string = function
| ADDR_UNIX path -> path
| ADDR_INET (address, port) ->
Printf.sprintf "%s:%i" (Unix.string_of_inet_addr address) port
let forward_body_general
(response : Dream.response)
(write_string : ?off:int -> ?len:int -> string -> unit)
(write_bigstring : ?off:int -> ?len:int -> Dream.bigstring -> unit)
http_flush
close =
let rec send () =
response
|> Dream.next
~bigstring
~string
~flush
~close
~exn:ignore
and bigstring chunk off len =
write_bigstring ~off ~len chunk;
send ()
and string chunk off len =
write_string ~off ~len chunk;
send ()
and flush () =
http_flush send
in
send ()
let forward_body
(response : Dream.response)
(body : [ `write ] Httpaf.Body.t) =
forward_body_general
response
(Httpaf.Body.write_string body)
(Httpaf.Body.write_bigstring body)
(Httpaf.Body.flush body)
(fun () -> Httpaf.Body.close_writer body)
let forward_body_h2
(response : Dream.response)
(body : [ `write ] H2.Body.t) =
forward_body_general
response
(H2.Body.write_string body)
(H2.Body.write_bigstring body)
(H2.Body.flush body)
(fun () -> H2.Body.close_writer body)