diff --git a/Docker/config.ini b/Docker/config.ini index 7dc52c21d57..f58a60c31da 100644 --- a/Docker/config.ini +++ b/Docker/config.ini @@ -20,6 +20,9 @@ shared-file-size = 8192 # The local IP and port to listen for incoming http connections. http-server-endpoint = 0.0.0.0:8888 +# The Access-Control-Allow-Origin http value +# access-control-allow-origin = * + # The local IP address and port to listen for incoming connections. listen-endpoint = 0.0.0.0:9876 diff --git a/plugins/http_plugin/http_plugin.cpp b/plugins/http_plugin/http_plugin.cpp index 75b66a60df3..c3ca40493d7 100644 --- a/plugins/http_plugin/http_plugin.cpp +++ b/plugins/http_plugin/http_plugin.cpp @@ -80,6 +80,7 @@ namespace eos { //asio::io_service http_ios; map url_handlers; optional listen_endpoint; + string access_control_allow_origin; websocket_server_type server; }; @@ -91,6 +92,8 @@ namespace eos { cfg.add_options() ("http-server-endpoint", bpo::value()->default_value("127.0.0.1:8888"), "The local IP and port to listen for incoming http connections.") + ("access-control-allow-origin", bpo::value(), + "Specify the Access-Control-Allow-Origin to be returned on each request.") ; } @@ -112,6 +115,11 @@ namespace eos { ilog("configured http to listen on ${h}:${p}", ("h",host)("p",port)); } + if (options.count("access-control-allow-origin")) { + my->access_control_allow_origin = options.at("access-control-allow-origin").as(); + ilog("configured http with access-control-allow-origin : ${o}", ("o", my->access_control_allow_origin)); + } + // uint32_t addr = my->listen_endpoint->address().to_v4().to_ulong(); // auto fcep = fc::ip::endpoint (addr,my->listen_endpoint->port()); } @@ -133,6 +141,9 @@ namespace eos { //ilog("handle http request: ${url}", ("url",con->get_uri()->str())); //ilog("${body}", ("body", con->get_request_body())); + if (!my->access_control_allow_origin.empty()) { + con->append_header("Access-Control-Allow-Origin", my->access_control_allow_origin); + } auto body = con->get_request_body(); auto resource = con->get_uri()->get_resource(); auto handler_itr = my->url_handlers.find(resource);