My agentic slop goes here. Not intended for anyone else!
1(** Connection pooling for efficient JMAP client connection reuse.
2
3 This module provides connection pooling functionality to reuse HTTP connections
4 and reduce the overhead of establishing new connections for each JMAP request.
5 It supports connection timeouts, health checks, and automatic cleanup.
6
7 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-3.3> RFC 8620, Section 3.3
8*)
9
10(** Statistics for connection pool monitoring *)
11type pool_stats = {
12 total_connections : int; (** Total connections in pool *)
13 active_connections : int; (** Currently active connections *)
14 idle_connections : int; (** Currently idle connections *)
15 total_requests : int; (** Total requests processed *)
16 cache_hits : int; (** Requests served from cached connections *)
17 cache_misses : int; (** Requests requiring new connections *)
18 connection_failures : int; (** Failed connection attempts *)
19}
20
21(** TLS configuration options *)
22type tls_config = {
23 authenticator : X509.Authenticator.t option; (** Custom TLS authenticator *)
24 certificates : Tls.Config.own_cert list; (** Client certificates for mutual TLS *)
25 ciphers : Tls.Ciphersuite.ciphersuite list option; (** Allowed cipher suites *)
26 version : (Tls.Core.tls_version * Tls.Core.tls_version) option; (** Min and max TLS versions *)
27 alpn_protocols : string list option; (** ALPN protocol list *)
28}
29
30(** Connection pool configuration *)
31type pool_config = {
32 max_connections : int; (** Maximum total connections *)
33 max_idle_connections : int; (** Maximum idle connections to keep *)
34 connection_timeout : float; (** Connection establishment timeout (seconds) *)
35 idle_timeout : float; (** Time to keep idle connections (seconds) *)
36 max_lifetime : float; (** Maximum connection lifetime (seconds) *)
37 health_check_interval : float; (** Health check interval (seconds) *)
38 enable_keep_alive : bool; (** Enable HTTP keep-alive *)
39}
40
41(** Connection pool type - opaque *)
42type t
43
44(** Create default pool configuration *)
45val default_config : unit -> pool_config
46
47(** Create a new connection pool.
48 @param config Pool configuration options
49 @param sw Eio switch for resource management
50 @return New connection pool *)
51val create :
52 ?config:pool_config ->
53 sw:Eio.Switch.t ->
54 unit ->
55 t
56
57(** Perform HTTP request using pooled connection.
58 @param pool The connection pool to use
59 @param env Eio environment for network operations
60 @param method_ HTTP method to use
61 @param uri Target URI for the request
62 @param headers HTTP headers to send
63 @param body Optional request body
64 @param tls_config Optional TLS configuration
65 @return HTTP response body or error *)
66val http_request_with_pool :
67 t ->
68 env:< net : 'a Eio.Net.t ; .. > ->
69 method_:Http.Method.t ->
70 uri:Uri.t ->
71 headers:(string * string) list ->
72 body:string option ->
73 tls_config:tls_config option ->
74 (string, Jmap.Error.error) result
75
76(** Get pool statistics for monitoring.
77 @param pool The connection pool
78 @return Current pool statistics *)
79val get_stats : t -> pool_stats
80
81(** Close all connections and clean up pool.
82 @param pool The connection pool to close *)
83val close : t -> unit