@@ -8,6 +8,7 @@ module Server = Http_miou_server
8
8
module Version = H1. Version
9
9
module Status = H2. Status
10
10
module Headers = H2. Headers
11
+ module Method = H2. Method
11
12
12
13
let ( % ) f g x = f (g x)
13
14
@@ -107,6 +108,8 @@ let add_authentication ?(meth = `Basic) ~add headers user_pass =
107
108
108
109
let user_agent = " hurl/%%VERSION_NUM%%"
109
110
111
+ type request = { meth : Method .t ; target : string ; headers : Headers .t }
112
+
110
113
type response = {
111
114
version : Version .t
112
115
; status : Status .t
@@ -135,7 +138,7 @@ let pp_error ppf = function
135
138
136
139
type body = String of string | Stream of string Seq .t
137
140
type meta = (Ipaddr .t * int ) * Tls.Core .epoch_data option
138
- type 'a handler = meta -> response -> 'a -> string option -> 'a
141
+ type 'a handler = meta -> request -> response -> 'a -> string option -> 'a
139
142
140
143
type config = {
141
144
meth : H2.Method .t
@@ -204,7 +207,7 @@ let prep_h2_headers cfg body =
204
207
let hdr = List. sort (fun (a , _ ) (b , _ ) -> String. compare a b) hdr in
205
208
H2.Headers. of_list hdr
206
209
207
- let from_h1 response =
210
+ let resp_from_h1 response =
208
211
{
209
212
version= response.H1.Response. version
210
213
; status= (response.H1.Response. status :> H2.Status.t )
@@ -213,14 +216,28 @@ let from_h1 response =
213
216
H2.Headers. of_list (H1.Headers. to_list response.H1.Response. headers)
214
217
}
215
218
216
- let from_h2 response =
219
+ let req_from_h1 req =
220
+ {
221
+ meth= req.H1.Request. meth
222
+ ; target= req.H1.Request. target
223
+ ; headers= H2.Headers. of_list (H1.Headers. to_list req.H1.Request. headers)
224
+ }
225
+
226
+ let resp_from_h2 response =
217
227
{
218
228
version= { major= 2 ; minor= 0 }
219
229
; status= response.H2.Response. status
220
230
; reason= H2.Status. to_string response.H2.Response. status
221
231
; headers= response.H2.Response. headers
222
232
}
223
233
234
+ let req_from_h2 req =
235
+ {
236
+ meth= req.H2.Request. meth
237
+ ; target= req.H2.Request. target
238
+ ; headers= req.H2.Request. headers
239
+ }
240
+
224
241
let _is_a_valid_redirection resp ~uri =
225
242
if Status. is_redirection resp.status then
226
243
match Headers. get resp.headers " location" with
@@ -253,7 +270,7 @@ let[@warning "-8"] single_http_1_1_request ?(config = H1.Config.default) flow
253
270
let request = H1.Request. create ~headers meth path in
254
271
let meta = ((cfg.ipaddr, cfg.port), cfg.epoch) in
255
272
let f (`V1 resp : Client.response ) acc str =
256
- fn meta (from_h1 resp) acc (Some str)
273
+ fn meta (req_from_h1 request) (resp_from_h1 resp) acc (Some str)
257
274
in
258
275
let finally () =
259
276
Log. debug (fun m -> m " close the underlying socket" );
@@ -283,8 +300,9 @@ let[@warning "-8"] single_http_1_1_request ?(config = H1.Config.default) flow
283
300
let * resp = Result. map_error (on_error % fst) resp in
284
301
let * () = Result. map_error on_error (Miou. await sender) in
285
302
let * () = Result. map_error on_error (Miou. await process) in
286
- let resp = from_h1 resp in
287
- Ok (resp, fn meta resp ! acc None )
303
+ let req = req_from_h1 request in
304
+ let resp = resp_from_h1 resp in
305
+ Ok (resp, fn meta req resp ! acc None )
288
306
289
307
let h2_writer body seq () =
290
308
let rec next seq reason =
@@ -313,7 +331,7 @@ let[@warning "-8"] single_h2_request ?(config = H2.Config.default) flow cfg
313
331
let request = H2.Request. create ~scheme ~headers meth path in
314
332
let meta = ((cfg.ipaddr, cfg.port), cfg.epoch) in
315
333
let f (`V2 response : Client.response ) acc str =
316
- fn meta (from_h2 response) acc (Some str)
334
+ fn meta (req_from_h2 request) (resp_from_h2 response) acc (Some str)
317
335
in
318
336
let (Client. Process { version= V2 ; acc; response; body; process; _ }) =
319
337
Client. run ~f acc (`V2 config) flow (`V2 request)
@@ -336,8 +354,9 @@ let[@warning "-8"] single_h2_request ?(config = H2.Config.default) flow cfg
336
354
let * resp = Result. map_error (on_error % fst) resp in
337
355
let * () = Result. map_error on_error (Miou. await sender) in
338
356
let * () = Result. map_error on_error (Miou. await process) in
339
- let resp = from_h2 resp in
340
- Ok (resp, fn meta resp ! acc None )
357
+ let req = req_from_h2 request in
358
+ let resp = resp_from_h2 resp in
359
+ Ok (resp, fn meta req resp ! acc None )
341
360
342
361
let alpn_protocol = function
343
362
| `Tcp _ -> None
0 commit comments