My agentic slop goes here. Not intended for anyone else!

more

Changed files
+80 -16
stack
+6
stack/requests/lib/cookie_jar.ml
···
Eio.Mutex.unlock t.mutex;
Log.info (fun m -> m "Cleared %d session cookies" removed)
+
let count t =
+
Eio.Mutex.lock t.mutex;
+
let n = List.length t.cookies in
+
Eio.Mutex.unlock t.mutex;
+
n
+
(** {1 Mozilla Format} *)
let to_mozilla_format_internal t =
+3
stack/requests/lib/cookie_jar.mli
···
(** Clear session cookies (those without expiry) *)
val clear_session_cookies : t -> unit
+
(** Get the number of cookies in the jar *)
+
val count : t -> int
+
(** {1 Cookie Creation} *)
(** Parse Set-Cookie header value into a cookie *)
+45 -10
stack/requests/lib/session.ml
···
(** {1 Types} *)
+
(** Session statistics *)
+
module Stats = struct
+
type t = {
+
requests_made : int;
+
total_time : float;
+
cookies_count : int;
+
retries_count : int;
+
}
+
+
let requests_made t = t.requests_made
+
let total_time t = t.total_time
+
let cookies_count t = t.cookies_count
+
let retries_count t = t.retries_count
+
+
let pp ppf t =
+
Format.fprintf ppf "@[<v>Session Statistics:@,\
+
requests made: %d@,\
+
total time: %.3fs@,\
+
cookies: %d@,\
+
retries: %d@]"
+
t.requests_made
+
t.total_time
+
t.cookies_count
+
t.retries_count
+
end
+
type ('clock, 'net) t = {
sw : Eio.Switch.t;
client : ('clock, 'net) Client.t;
···
~config:retry_config
~f:make_request
~should_retry_exn:(function
-
(* TODO: Handle Stream exceptions once Stream module is properly imported *)
+
(* Retry on retryable errors *)
+
| Error.Timeout -> true
+
| Error.ConnectionError _ -> true
+
| Error.HTTPError { status; _ } when status >= 500 -> true (* Server errors *)
+
| Error.SSLError _ -> false (* Don't retry SSL errors *)
+
| Error.ProxyError _ -> true
+
| Eio.Io (Eio.Net.E (Connection_reset _), _) -> true
+
| Eio.Time.Timeout -> true
| _ -> false)
in
···
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
-
(* TODO: Add progress tracking wrapper around source *)
+
(* Progress tracking would require wrapping Eio.Flow.source which is complex.
+
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
-
(* TODO: Add progress tracking wrapper *)
+
(* Progress tracking would require intercepting Eio.Flow.copy.
+
Use Client.download with on_progress callback for progress tracking instead. *)
Eio.Flow.copy body sink
let download_file t ?headers ?auth ?timeout url path =
···
let pp ppf t =
Mutex.lock t.mutex;
let stats = t.requests_made, t.total_time,
-
(match t.cookie_jar with _jar -> 0) in (* TODO: Get actual count *)
+
Cookie_jar.count t.cookie_jar in
Mutex.unlock t.mutex;
let requests, time, cookies = stats in
Format.fprintf ppf "@[<v>Session:@,\
···
let stats t =
Mutex.lock t.mutex;
-
let result = object
-
method requests_made = t.requests_made
-
method total_time = t.total_time
-
method cookies_count = 0 (* TODO: Get from cookie jar *)
-
method retries_count = t.retries_count
-
end in
+
let result = Stats.{
+
requests_made = t.requests_made;
+
total_time = t.total_time;
+
cookies_count = Cookie_jar.count t.cookie_jar;
+
retries_count = t.retries_count;
+
} in
Mutex.unlock t.mutex;
result
+26 -6
stack/requests/lib/session.mli
···
type ('clock, 'net) t
(** A session maintains state across multiple HTTP requests *)
+
(** Session statistics *)
+
module Stats : sig
+
type t = {
+
requests_made : int; (** Total number of requests made *)
+
total_time : float; (** Total time spent in requests (seconds) *)
+
cookies_count : int; (** Number of cookies in the jar *)
+
retries_count : int; (** Total number of retries performed *)
+
}
+
+
(** Get the number of requests made *)
+
val requests_made : t -> int
+
+
(** Get the total time spent in requests *)
+
val total_time : t -> float
+
+
(** Get the number of cookies *)
+
val cookies_count : t -> int
+
+
(** Get the number of retries *)
+
val retries_count : t -> int
+
+
(** Pretty printer for statistics *)
+
val pp : Format.formatter -> t -> unit
+
end
+
(** {1 Session Creation and Configuration} *)
val create :
···
val pp : Format.formatter -> ('clock, 'net) t -> unit
(** Pretty print session configuration *)
-
val stats : ('clock, 'net) t -> <
-
requests_made : int;
-
total_time : float;
-
cookies_count : int;
-
retries_count : int;
-
>
+
val stats : ('clock, 'net) t -> Stats.t
(** Get session statistics *)
(** {1 Examples} *)