···
let method_str = Method.to_string method_ in
Log.info (fun m -> m "Making %s request to %s" method_str url);
128
-
let uri = Uri.of_string url in
129
-
let host = match Uri.host uri with
131
-
| None -> failwith "URL must contain a host"
133
-
let port = match Uri.scheme uri, Uri.port uri with
134
-
| Some "https", None -> 443
135
-
| Some "https", Some p -> p
136
-
| Some "http", None -> 80
137
-
| Some "http", Some p -> p
let headers = match headers with
···
164
-
(* Create endpoint for connection pool *)
165
-
let endpoint = Conpool.Endpoint.make ~host ~port in
(* Convert body to string for sending *)
let request_body_str = match body with
| Some b -> Body.Private.to_string b
173
-
(* Determine if we need TLS based on URL scheme and choose appropriate pool *)
174
-
let is_https = match Uri.scheme uri with
175
-
| Some "https" -> true
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
159
+
(* Parse the redirect URL to get correct host and port *)
160
+
let redirect_host = match Uri.host uri_to_fetch with
162
+
| None -> failwith "Redirect URL must contain a host"
164
+
let redirect_port = match Uri.scheme uri_to_fetch, Uri.port uri_to_fetch with
165
+
| Some "https", None -> 443
166
+
| Some "https", Some p -> p
167
+
| Some "http", None -> 80
168
+
| Some "http", Some p -> p
173
+
(* Create endpoint for this specific URL *)
174
+
let endpoint = Conpool.Endpoint.make ~host:redirect_host ~port:redirect_port in
176
+
(* Determine if we need TLS based on this URL's scheme *)
177
+
let is_https = match Uri.scheme uri_to_fetch with
178
+
| Some "https" -> true
182
+
(* Choose the appropriate connection pool for this URL *)
183
+
let pool = if is_https then client.https_pool else client.http_pool in
Conpool.with_connection pool endpoint (fun flow ->