···124124 let method_str = Method.to_string method_ in
125125 Log.info (fun m -> m "Making %s request to %s" method_str url);
126126127127- (* Parse URI *)
128128- let uri = Uri.of_string url in
129129- let host = match Uri.host uri with
130130- | Some h -> h
131131- | None -> failwith "URL must contain a host"
132132- in
133133- let port = match Uri.scheme uri, Uri.port uri with
134134- | Some "https", None -> 443
135135- | Some "https", Some p -> p
136136- | Some "http", None -> 80
137137- | Some "http", Some p -> p
138138- | _, Some p -> p
139139- | _ -> 80
140140- in
141141-142127 (* Prepare headers *)
143128 let headers = match headers with
144129 | Some h -> h
···161146 | None -> headers
162147 in
163148164164- (* Create endpoint for connection pool *)
165165- let endpoint = Conpool.Endpoint.make ~host ~port in
166166-167149 (* Convert body to string for sending *)
168150 let request_body_str = match body with
169151 | None -> ""
170152 | Some b -> Body.Private.to_string b
171153 in
172172-173173- (* Determine if we need TLS based on URL scheme and choose appropriate pool *)
174174- let is_https = match Uri.scheme uri with
175175- | Some "https" -> true
176176- | _ -> false
177177- in
178178-179179- (* Choose the appropriate connection pool *)
180180- let pool = if is_https then client.https_pool else client.http_pool in
181154182155 (* Execute request with pooled connection *)
183156 let rec make_with_redirects url_to_fetch redirects_left =
184157 let uri_to_fetch = Uri.of_string url_to_fetch in
158158+159159+ (* Parse the redirect URL to get correct host and port *)
160160+ let redirect_host = match Uri.host uri_to_fetch with
161161+ | Some h -> h
162162+ | None -> failwith "Redirect URL must contain a host"
163163+ in
164164+ let redirect_port = match Uri.scheme uri_to_fetch, Uri.port uri_to_fetch with
165165+ | Some "https", None -> 443
166166+ | Some "https", Some p -> p
167167+ | Some "http", None -> 80
168168+ | Some "http", Some p -> p
169169+ | _, Some p -> p
170170+ | _ -> 80
171171+ in
172172+173173+ (* Create endpoint for this specific URL *)
174174+ let endpoint = Conpool.Endpoint.make ~host:redirect_host ~port:redirect_port in
175175+176176+ (* Determine if we need TLS based on this URL's scheme *)
177177+ let is_https = match Uri.scheme uri_to_fetch with
178178+ | Some "https" -> true
179179+ | _ -> false
180180+ in
181181+182182+ (* Choose the appropriate connection pool for this URL *)
183183+ let pool = if is_https then client.https_pool else client.http_pool in
185184186185 let make_request_fn () =
187186 Conpool.with_connection pool endpoint (fun flow ->