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).
This commit is contained in:
Hannes Mehnert 2022-09-01 09:27:03 +02:00
parent 86c961f5cf
commit c16f2288ed

View file

@ -323,16 +323,17 @@ let one_request
then single_request ~ctx ~alpn_protocol ?config tls_config ~meth ~headers ?body uri then single_request ~ctx ~alpn_protocol ?config tls_config ~meth ~headers ?body uri
else else
let rec follow_redirect count uri = 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 else
single_request ~ctx ~alpn_protocol ?config tls_config ~meth ~headers ?body uri single_request ~ctx ~alpn_protocol ?config tls_config ~meth ~headers ?body uri
>>? fun (resp, body) -> >>? fun (resp, body) ->
match resp.status with if Status.is_redirection resp.status then
| #Status.redirection ->
( match Headers.get resp.headers "location" with ( match Headers.get resp.headers "location" with
| Some location -> | Some location ->
Lwt.return (resolve_location ~uri ~location) >>? fun uri -> Lwt.return (resolve_location ~uri ~location) >>? fun uri ->
follow_redirect (pred count) uri follow_redirect (pred count) uri
| None -> Lwt.return_ok (resp, body) ) | None ->
| _ -> Lwt.return_ok (resp, body) in Lwt.return_ok (resp, body) )
else
Lwt.return_ok (resp, body) in
follow_redirect max_redirect uri follow_redirect max_redirect uri