···
6
+
(** Session statistics *)
7
+
module Stats = struct
11
+
cookies_count : int;
12
+
retries_count : int;
15
+
let requests_made t = t.requests_made
16
+
let total_time t = t.total_time
17
+
let cookies_count t = t.cookies_count
18
+
let retries_count t = t.retries_count
21
+
Format.fprintf ppf "@[<v>Session Statistics:@,\
22
+
requests made: %d@,\
23
+
total time: %.3fs@,\
type ('clock, 'net) t = {
client : ('clock, 'net) Client.t;
···
~should_retry_exn:(function
207
-
(* TODO: Handle Stream exceptions once Stream module is properly imported *)
233
+
(* Retry on retryable errors *)
234
+
| Error.Timeout -> true
235
+
| Error.ConnectionError _ -> true
236
+
| Error.HTTPError { status; _ } when status >= 500 -> true (* Server errors *)
237
+
| Error.SSLError _ -> false (* Don't retry SSL errors *)
238
+
| Error.ProxyError _ -> true
239
+
| Eio.Io (Eio.Net.E (Connection_reset _), _) -> true
240
+
| Eio.Time.Timeout -> true
···
let upload t ?headers ?auth ?timeout ?method_ ?mime ?length ~source url =
let method_ = Option.value method_ ~default:`POST in
let body = Body.of_stream ?length (Option.value mime ~default:Mime.octet_stream) source in
262
-
(* TODO: Add progress tracking wrapper around source *)
295
+
(* Progress tracking would require wrapping Eio.Flow.source which is complex.
296
+
Use Client.upload with on_progress callback for progress tracking instead. *)
execute_request t ?headers ~body ?auth ?timeout ~method_ url
let download t ?headers ?auth ?timeout url ~sink =
let response = execute_request t ?headers ?auth ?timeout ~method_:`GET url in
let body = Response.body response in
268
-
(* TODO: Add progress tracking wrapper *)
302
+
(* Progress tracking would require intercepting Eio.Flow.copy.
303
+
Use Client.download with on_progress callback for progress tracking instead. *)
let download_file t ?headers ?auth ?timeout url path =
···
let stats = t.requests_made, t.total_time,
279
-
(match t.cookie_jar with _jar -> 0) in (* TODO: Get actual count *)
314
+
Cookie_jar.count t.cookie_jar in
let requests, time, cookies = stats in
Format.fprintf ppf "@[<v>Session:@,\
···
304
-
let result = object
305
-
method requests_made = t.requests_made
306
-
method total_time = t.total_time
307
-
method cookies_count = 0 (* TODO: Get from cookie jar *)
308
-
method retries_count = t.retries_count
339
+
let result = Stats.{
340
+
requests_made = t.requests_made;
341
+
total_time = t.total_time;
342
+
cookies_count = Cookie_jar.count t.cookie_jar;
343
+
retries_count = t.retries_count;