···
let method_str = Method.to_string method_ in
Log.info (fun m -> m "Making %s request to %s" method_str url);
let headers = match headers with
···
(* Convert body to string for sending *)
let request_body_str = match body with
| Some b -> Body.Private.to_string b
(* 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
+
(* Parse the redirect URL to get correct host and port *)
+
let redirect_host = match Uri.host uri_to_fetch with
+
| None -> failwith "Redirect URL must contain a host"
+
let redirect_port = match Uri.scheme uri_to_fetch, Uri.port uri_to_fetch with
+
| Some "https", None -> 443
+
| Some "https", Some p -> p
+
| Some "http", None -> 80
+
| Some "http", Some p -> p
+
(* Create endpoint for this specific URL *)
+
let endpoint = Conpool.Endpoint.make ~host:redirect_host ~port:redirect_port in
+
(* Determine if we need TLS based on this URL's scheme *)
+
let is_https = match Uri.scheme uri_to_fetch with
+
(* Choose the appropriate connection pool for this URL *)
+
let pool = if is_https then client.https_pool else client.http_pool in
Conpool.with_connection pool endpoint (fun flow ->