Something went wrong. Try again.
A batteries included HTTP/1.1 client in OCaml
Something went wrong. Try again.
1.4 kB · 50 lines
OCaml
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051(*--------------------------------------------------------------------------- Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. SPDX-License-Identifier: ISC ---------------------------------------------------------------------------*)
let src = Logs.Src.create "requests.timeout" ~doc:"HTTP Request Timeouts"
module Log = (val Logs.src_log src : Logs.LOG)
type t = { connect : float option; read : float option; total : float option; expect_100_continue : float option; (** Timeout for 100-continue response *)}
let none = { connect = None; read = None; total = None; expect_100_continue = None }
let v ?connect ?read ?total ?expect_100_continue () = { connect; read; total; expect_100_continue }
let default = { connect = Some 10.0; read = Some 30.0; total = None; expect_100_continue = Some 1.0; (* 1 second default for 100-continue *) }
let connect t = t.connectlet read t = t.readlet total t = t.totallet expect_100_continue t = t.expect_100_continue
let pp ppf t = let fmt_opt name = Option.map (Fmt.str "%s:%.1fs" name) in let items = List.filter_map Fun.id [ fmt_opt "connect" t.connect; fmt_opt "read" t.read; fmt_opt "total" t.total; fmt_opt "expect" t.expect_100_continue; ] in match items with | [] -> Fmt.pf ppf "no timeouts" | _ -> Fmt.pf ppf "%s" (String.concat ", " items)