From bd6c9edff6250c2cf775e2675710740944408061 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Tue, 5 Nov 2024 11:00:03 +0100 Subject: [PATCH 1/2] if a redirect with a body is provided, we need to skip the body --- src/http_mirage_client.ml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/http_mirage_client.ml b/src/http_mirage_client.ml index 476e140..72468b5 100644 --- a/src/http_mirage_client.ml +++ b/src/http_mirage_client.ml @@ -434,6 +434,12 @@ let request let rec follow_redirect count uri = if count = 0 then Lwt.return_error (`Msg "Redirect limit exceeded") else + let f response acc body = + if Status.is_redirection response.status then + Lwt.return acc + else + f response acc body + in single_request ~ctx ~alpn_protocol ?config tls_config ~meth ~headers ?body uri f f_init >>? fun (resp, body) -> -- 2.47.0 From 0009c1eeaded97b48df6527ea4c9c3ebf90e80e0 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Tue, 5 Nov 2024 12:26:16 +0100 Subject: [PATCH 2/2] clarify how f and follow_redirect interact --- src/http_mirage_client.mli | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/http_mirage_client.mli b/src/http_mirage_client.mli index f0ef229..165f2cd 100644 --- a/src/http_mirage_client.mli +++ b/src/http_mirage_client.mli @@ -40,4 +40,6 @@ val request : ~max_redirect ~follow_redirect url body_f body_init] does a HTTP request to [url] using [meth] and the HTTP protocol in [config]. The response is the value of this function. The body is provided in chunks (see [body_f]). + If [follow_redirect] is enabled (true by default), [body_f] is not called + with the potential body of the redirection. Reasonably defaults are used if not provided. *) -- 2.47.0