From c16f2288edbde02a5442699dfaeeebd48f52d941 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Thu, 1 Sep 2022 09:27:03 +0200 Subject: [PATCH] Use Status.is_redirection instead of matching on the polymorphic variant The reason behind this is that the new HTTP code 308 (permanent redirect) is not recognized by HTTP/AF, but already used (e.g. by alt-ergo.ocamlpro.com). --- mirage/http_mirage_client.ml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mirage/http_mirage_client.ml b/mirage/http_mirage_client.ml index b00b8c2..eb041b3 100644 --- a/mirage/http_mirage_client.ml +++ b/mirage/http_mirage_client.ml @@ -323,16 +323,17 @@ let one_request then single_request ~ctx ~alpn_protocol ?config tls_config ~meth ~headers ?body uri else let rec follow_redirect count uri = - if count = 0 then Lwt.return_error (`Msg "Redirect limit exceeded") + if count = 0 then Lwt.return_error (`Msg "Redirect limit exceeded") else single_request ~ctx ~alpn_protocol ?config tls_config ~meth ~headers ?body uri >>? fun (resp, body) -> - match resp.status with - | #Status.redirection -> + if Status.is_redirection resp.status then ( match Headers.get resp.headers "location" with | Some location -> Lwt.return (resolve_location ~uri ~location) >>? fun uri -> follow_redirect (pred count) uri - | None -> Lwt.return_ok (resp, body) ) - | _ -> Lwt.return_ok (resp, body) in + | None -> + Lwt.return_ok (resp, body) ) + else + Lwt.return_ok (resp, body) in follow_redirect max_redirect uri