Skip to content

Commit

Permalink
doi2bib: drain body
Browse files Browse the repository at this point in the history
  • Loading branch information
mseri authored Mar 24, 2021
1 parent db6c55a commit c8815b3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions bin/doi2bib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,24 @@ let rec get ?headers ?fallback uri =
let* body = Cohttp_lwt.Body.to_string body in
Lwt.return body
| 302 ->
let* () = Cohttp_lwt.Body.drain_body body in
let uri' = Cohttp_lwt.(resp |> Response.headers |> Cohttp.Header.get_location) in
(match uri', fallback with
| Some uri, _ -> get ?headers ?fallback uri
| None, Some uri -> get ?headers uri
| None, None ->
Lwt.fail_with ("Malformed redirection trying to access '" ^ Uri.to_string uri ^ "'."))
| d when (d = 404 || d = 504) && Option.is_some fallback ->
(match fallback with
(let* () = Cohttp_lwt.Body.drain_body body in
match fallback with
| Some uri -> get ?headers uri
| None -> assert false)
| 400 | 404 -> Lwt.fail Entry_not_found
| 502 -> Lwt.fail Bad_gateway
| 400 | 404 ->
let* () = Cohttp_lwt.Body.drain_body body in
Lwt.fail Entry_not_found
| 502 ->
let* () = Cohttp_lwt.Body.drain_body body in
Lwt.fail Bad_gateway
| _ ->
Lwt.fail_with
("Response error: got '"
Expand Down

0 comments on commit c8815b3

Please sign in to comment.