Signer: allow client to send host header

This commit is contained in:
Benjamin Canou 2018-06-27 22:37:34 +02:00
parent 1f213b385b
commit 5696105d14

View File

@ -28,7 +28,7 @@ module Make(N : sig val scheme : string end) = struct
^ " - " ^ scheme ^ "://host/tz1...\n" ^ " - " ^ scheme ^ "://host/tz1...\n"
^ " - " ^ scheme ^ "://host:port/path/to/service/tz1...\n" ^ " - " ^ scheme ^ "://host:port/path/to/service/tz1...\n"
^ "Environment variable TEZOS_SIGNER_HTTP_HEADERS can be specified \ ^ "Environment variable TEZOS_SIGNER_HTTP_HEADERS can be specified \
to add headers to the requests (only custom 'x-...' headers are supported)." to add headers to the requests (only 'host' and custom 'x-...' headers are supported)."
let headers = match Sys.getenv_opt "TEZOS_SIGNER_HTTP_HEADERS" with let headers = match Sys.getenv_opt "TEZOS_SIGNER_HTTP_HEADERS" with
| None -> None | None -> None
@ -42,10 +42,13 @@ module Make(N : sig val scheme : string end) = struct
"Http signer: invalid TEZOS_SIGNER_HTTP_HEADERS environment variable, missing colon" "Http signer: invalid TEZOS_SIGNER_HTTP_HEADERS environment variable, missing colon"
| Some pos -> | Some pos ->
let header = String.trim (String.sub line 0 pos) in let header = String.trim (String.sub line 0 pos) in
if String.length header < 2 let header = String.lowercase_ascii header in
|| String.sub (String.lowercase_ascii header) 0 2 <> "x-" then if header <> "host"
&& (String.length header < 2
|| String.sub header 0 2 <> "x-") then
Pervasives.failwith Pervasives.failwith
"Http signer: invalid TEZOS_SIGNER_HTTP_HEADERS environment variable, only x- headers are supported" ; "Http signer: invalid TEZOS_SIGNER_HTTP_HEADERS environment variable, \
only 'host' or 'x-' headers are supported" ;
let value = String.trim (String.sub line (pos + 1) (String.length line - pos - 1)) in let value = String.trim (String.sub line (pos + 1) (String.length line - pos - 1)) in
(header, value) :: acc) [] lines) (header, value) :: acc) [] lines)