this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

more

+80 -16
+6
stack/requests/lib/cookie_jar.ml
··· 261 261 Eio.Mutex.unlock t.mutex; 262 262 Log.info (fun m -> m "Cleared %d session cookies" removed) 263 263 264 + let count t = 265 + Eio.Mutex.lock t.mutex; 266 + let n = List.length t.cookies in 267 + Eio.Mutex.unlock t.mutex; 268 + n 269 + 264 270 (** {1 Mozilla Format} *) 265 271 266 272 let to_mozilla_format_internal t =
+3
stack/requests/lib/cookie_jar.mli
··· 58 58 (** Clear session cookies (those without expiry) *) 59 59 val clear_session_cookies : t -> unit 60 60 61 + (** Get the number of cookies in the jar *) 62 + val count : t -> int 63 + 61 64 (** {1 Cookie Creation} *) 62 65 63 66 (** Parse Set-Cookie header value into a cookie *)
+45 -10
stack/requests/lib/session.ml
··· 3 3 4 4 (** {1 Types} *) 5 5 6 + (** Session statistics *) 7 + module Stats = struct 8 + type t = { 9 + requests_made : int; 10 + total_time : float; 11 + cookies_count : int; 12 + retries_count : int; 13 + } 14 + 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 19 + 20 + let pp ppf t = 21 + Format.fprintf ppf "@[<v>Session Statistics:@,\ 22 + requests made: %d@,\ 23 + total time: %.3fs@,\ 24 + cookies: %d@,\ 25 + retries: %d@]" 26 + t.requests_made 27 + t.total_time 28 + t.cookies_count 29 + t.retries_count 30 + end 31 + 6 32 type ('clock, 'net) t = { 7 33 sw : Eio.Switch.t; 8 34 client : ('clock, 'net) Client.t; ··· 204 230 ~config:retry_config 205 231 ~f:make_request 206 232 ~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 208 241 | _ -> false) 209 242 in 210 243 ··· 259 292 let upload t ?headers ?auth ?timeout ?method_ ?mime ?length ~source url = 260 293 let method_ = Option.value method_ ~default:`POST in 261 294 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. *) 263 297 execute_request t ?headers ~body ?auth ?timeout ~method_ url 264 298 265 299 let download t ?headers ?auth ?timeout url ~sink = 266 300 let response = execute_request t ?headers ?auth ?timeout ~method_:`GET url in 267 301 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. *) 269 304 Eio.Flow.copy body sink 270 305 271 306 let download_file t ?headers ?auth ?timeout url path = ··· 276 311 let pp ppf t = 277 312 Mutex.lock t.mutex; 278 313 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 280 315 Mutex.unlock t.mutex; 281 316 let requests, time, cookies = stats in 282 317 Format.fprintf ppf "@[<v>Session:@,\ ··· 301 336 302 337 let stats t = 303 338 Mutex.lock t.mutex; 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 309 - end in 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; 344 + } in 310 345 Mutex.unlock t.mutex; 311 346 result 312 347
+26 -6
stack/requests/lib/session.mli
··· 30 30 type ('clock, 'net) t 31 31 (** A session maintains state across multiple HTTP requests *) 32 32 33 + (** Session statistics *) 34 + module Stats : sig 35 + type t = { 36 + requests_made : int; (** Total number of requests made *) 37 + total_time : float; (** Total time spent in requests (seconds) *) 38 + cookies_count : int; (** Number of cookies in the jar *) 39 + retries_count : int; (** Total number of retries performed *) 40 + } 41 + 42 + (** Get the number of requests made *) 43 + val requests_made : t -> int 44 + 45 + (** Get the total time spent in requests *) 46 + val total_time : t -> float 47 + 48 + (** Get the number of cookies *) 49 + val cookies_count : t -> int 50 + 51 + (** Get the number of retries *) 52 + val retries_count : t -> int 53 + 54 + (** Pretty printer for statistics *) 55 + val pp : Format.formatter -> t -> unit 56 + end 57 + 33 58 (** {1 Session Creation and Configuration} *) 34 59 35 60 val create : ··· 248 273 val pp : Format.formatter -> ('clock, 'net) t -> unit 249 274 (** Pretty print session configuration *) 250 275 251 - val stats : ('clock, 'net) t -> < 252 - requests_made : int; 253 - total_time : float; 254 - cookies_count : int; 255 - retries_count : int; 256 - > 276 + val stats : ('clock, 'net) t -> Stats.t 257 277 (** Get session statistics *) 258 278 259 279 (** {1 Examples} *)