Resto: Fix #480: Keep the host: set by the user with TEZOS_SIGNER_HTTP_HEADERS

This is a fixup of 21bb9436371741a8cf643cfc6218ace9ebfecc19
This commit is contained in:
Pierre Boutillier 2019-02-27 10:12:40 +01:00 committed by Pierre Boutillier
parent b4b97dada3
commit d7ba8bb07d

View File

@ -144,6 +144,15 @@ module Make (Encoding : Resto.ENCODING) = struct
}
let internal_call meth (log : log) ?(headers = []) ?accept ?body ?media uri : (content, content) generic_rest_result Lwt.t =
let host =
match Uri.host uri, Uri.port uri with
| None, _ -> None
| Some host, None -> Some host
| Some host, Some port -> Some (host ^ ":" ^ string_of_int port) in
let init_headers =
match host with
| None -> Header.init ()
| Some host -> Header.replace (Header.init ()) "host" host in
let headers = List.fold_left (fun headers (header, value) ->
let header = String.lowercase_ascii header in
if header <> "host"
@ -153,7 +162,7 @@ module Make (Encoding : Resto.ENCODING) = struct
"Resto_cohttp.Client.call: \
only headers \"host\" or starting with \"x-\" are supported"
else Header.replace headers header value)
(Header.init ()) headers in
init_headers headers in
let body, headers =
match body, media with
| None, _ -> Cohttp_lwt.Body.empty, headers
@ -166,15 +175,6 @@ module Make (Encoding : Resto.ENCODING) = struct
| None -> headers
| Some ranges ->
Header.add headers "accept" (Media_type.accept_header ranges) in
let host =
match Uri.host uri, Uri.port uri with
| None, _ -> None
| Some host, None -> Some host
| Some host, Some port -> Some (host ^ ":" ^ string_of_int port) in
let headers =
match host with
| None -> headers
| Some host -> Header.add headers "host" host in
Lwt.catch begin fun () ->
let rec call_and_retry_on_502 attempt delay =
Cohttp_lwt_unix.Client.call