From 64183bbcf33469db8b5700cf7894fb3f116ee7ca Mon Sep 17 00:00:00 2001 From: Vincent Bernardoff Date: Fri, 4 May 2018 16:34:29 +0200 Subject: [PATCH] RPC: CORS now accepts `Content-Type` by default --- src/bin_node/node_run_command.ml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/bin_node/node_run_command.ml b/src/bin_node/node_run_command.ml index 2334f7cba..791e1f1f7 100644 --- a/src/bin_node/node_run_command.ml +++ b/src/bin_node/node_run_command.ml @@ -188,6 +188,13 @@ let init_node ?sandbox (config : Node_config_file.t) = config.shell.prevalidator_limits config.shell.chain_validator_limits +(* Add default accepted CORS headers *) +let sanitize_cors_headers ~default headers = + List.map String.lowercase_ascii headers |> + String.Set.of_list |> + String.Set.(union (of_list default)) |> + String.Set.elements + let init_rpc (rpc_config: Node_config_file.rpc) node = match rpc_config.listen_addr with | None -> @@ -210,12 +217,15 @@ let init_rpc (rpc_config: Node_config_file.rpc) node = "Starting the RPC server listening on port %d%s." port (if rpc_config.tls = None then "" else " (TLS enabled)") >>= fun () -> + let cors_headers = + sanitize_cors_headers + ~default:["Content-Type"] rpc_config.cors_headers in Lwt.catch (fun () -> RPC_server.launch ~host mode dir ~media_types:Media_type.all_media_types ~cors:{ allowed_origins = rpc_config.cors_origins ; - allowed_headers = rpc_config.cors_headers } >>= fun server -> + allowed_headers = cors_headers } >>= fun server -> return (Some server)) (function |Unix.Unix_error(Unix.EADDRINUSE, "bind","") ->