···
tls_config : Tls.Config.client option;
13
-
pool : ('clock, 'net) Conpool.t;
13
+
http_pool : ('clock, 'net) Conpool.t; (* For HTTP connections *)
14
+
https_pool : ('clock, 'net) Conpool.t; (* For HTTPS connections *)
···
49
-
(* Create connection pool - plain TCP, we'll wrap with TLS per-request *)
50
+
(* Create connection pools - one for HTTP, one for HTTPS *)
let pool_config = Conpool.Config.make
~max_connections_per_endpoint:max_connections_per_host
~max_idle_time:connection_idle_timeout
···
57
-
let pool = Conpool.create
58
+
(* HTTP pool - plain TCP connections *)
59
+
let http_pool = Conpool.create
67
+
(* HTTPS pool - TLS-wrapped connections *)
68
+
let https_tls_config = Option.map (fun cfg ->
69
+
Conpool.Tls_config.make ~config:cfg ()
72
+
let https_pool = Conpool.create
76
+
?tls:https_tls_config
65
-
Log.info (fun m -> m "Created HTTP client with connection pool (max_per_host=%d)"
66
-
max_connections_per_host);
81
+
Log.info (fun m -> m "Created HTTP client with connection pools (max_per_host=%d, TLS=%b)"
82
+
max_connections_per_host (Option.is_some https_tls_config));
···
let default ~sw ~clock ~net =
···
| Some b -> Body.Private.to_string b
156
-
(* Determine if we need TLS based on URL scheme *)
173
+
(* Determine if we need TLS based on URL scheme and choose appropriate pool *)
let is_https = match Uri.scheme uri with
179
+
(* Choose the appropriate connection pool *)
180
+
let pool = if is_https then client.https_pool else client.http_pool in
(* Execute request with pooled connection *)
let rec make_with_redirects url_to_fetch redirects_left =
let uri_to_fetch = Uri.of_string url_to_fetch in
167
-
Conpool.with_connection client.pool endpoint (fun tcp_flow ->
168
-
(* Wrap with TLS if HTTPS *)
169
-
let flow : Eio.Flow.two_way_ty Eio.Resource.t = if is_https then
170
-
match client.tls_config with
172
-
let domain = Domain_name.of_string_exn host in
173
-
let servername = Domain_name.host_exn domain in
174
-
(Tls_eio.client_of_flow ~host:servername tls_cfg tcp_flow :> Eio.Flow.two_way_ty Eio.Resource.t)
176
-
Log.warn (fun m -> m "HTTPS request but no TLS config available");
177
-
failwith "HTTPS requires TLS configuration"
179
-
(tcp_flow :> Eio.Flow.two_way_ty Eio.Resource.t)
187
+
Conpool.with_connection pool endpoint (fun flow ->
188
+
(* Flow is already TLS-wrapped if from https_pool, plain TCP if from http_pool *)
(* Use our low-level HTTP client *)
Http_client.make_request ~method_:method_str ~uri:uri_to_fetch ~headers ~body_str:request_body_str flow