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

more

Changed files
+30 -23
stack
requests
+29 -22
stack/requests/lib/one.ml
···
retry_backoff : float;
verify_tls : bool;
tls_config : Tls.Config.client option;
-
pool : ('clock, 'net) Conpool.t;
+
http_pool : ('clock, 'net) Conpool.t; (* For HTTP connections *)
+
https_pool : ('clock, 'net) Conpool.t; (* For HTTPS connections *)
}
let create
···
| None, false -> None
in
-
(* Create connection pool - plain TCP, we'll wrap with TLS per-request *)
+
(* 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
···
()
in
-
let pool = Conpool.create
+
(* HTTP pool - plain TCP connections *)
+
let http_pool = Conpool.create
+
~sw
+
~net
+
~clock
+
~config:pool_config
+
()
+
in
+
+
(* HTTPS pool - TLS-wrapped connections *)
+
let https_tls_config = Option.map (fun cfg ->
+
Conpool.Tls_config.make ~config:cfg ()
+
) tls_config in
+
+
let https_pool = Conpool.create
~sw
~net
~clock
+
?tls:https_tls_config
~config:pool_config
()
in
-
Log.info (fun m -> m "Created HTTP client with connection pool (max_per_host=%d)"
-
max_connections_per_host);
+
Log.info (fun m -> m "Created HTTP client with connection pools (max_per_host=%d, TLS=%b)"
+
max_connections_per_host (Option.is_some https_tls_config));
{
clock;
···
retry_backoff;
verify_tls;
tls_config;
-
pool;
+
http_pool;
+
https_pool;
}
let default ~sw ~clock ~net =
···
| Some b -> Body.Private.to_string b
in
-
(* Determine if we need TLS based on URL scheme *)
+
(* Determine if we need TLS based on URL scheme and choose appropriate pool *)
let is_https = match Uri.scheme uri with
| Some "https" -> true
| _ -> false
in
+
(* Choose the appropriate connection pool *)
+
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
let make_request_fn () =
-
Conpool.with_connection client.pool endpoint (fun tcp_flow ->
-
(* Wrap with TLS if HTTPS *)
-
let flow : Eio.Flow.two_way_ty Eio.Resource.t = if is_https then
-
match client.tls_config with
-
| Some tls_cfg ->
-
let domain = Domain_name.of_string_exn host in
-
let servername = Domain_name.host_exn domain in
-
(Tls_eio.client_of_flow ~host:servername tls_cfg tcp_flow :> Eio.Flow.two_way_ty Eio.Resource.t)
-
| None ->
-
Log.warn (fun m -> m "HTTPS request but no TLS config available");
-
failwith "HTTPS requires TLS configuration"
-
else
-
(tcp_flow :> Eio.Flow.two_way_ty Eio.Resource.t)
-
in
-
+
Conpool.with_connection pool endpoint (fun flow ->
+
(* 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
)
+1 -1
stack/requests/test/test_requests.ml
···
end in
Test_server.start_server ~port test_env;
-
let client = Requests.One.create ~clock:env#clock ~net:env#net () in
+
let client = Requests.One.create ~sw ~clock:env#clock ~net:env#net () in
let response = Requests.One.get ~sw ~client (base_url ^ "/echo") in
Alcotest.(check int) "One module status" 200 (Requests.Response.status_code response)