From d7ba8bb07dd687f460f619927429f8ee1ee9e16f Mon Sep 17 00:00:00 2001 From: Pierre Boutillier Date: Wed, 27 Feb 2019 10:12:40 +0100 Subject: [PATCH] Resto: Fix #480: Keep the `host:` set by the user with TEZOS_SIGNER_HTTP_HEADERS This is a fixup of 21bb9436371741a8cf643cfc6218ace9ebfecc19 --- .../ocplib-resto/lib_resto-cohttp/client.ml | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/vendors/ocplib-resto/lib_resto-cohttp/client.ml b/vendors/ocplib-resto/lib_resto-cohttp/client.ml index eafff1b1b..03290f720 100644 --- a/vendors/ocplib-resto/lib_resto-cohttp/client.ml +++ b/vendors/ocplib-resto/lib_resto-cohttp/client.ml @@ -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