Skip to content

Commit

Permalink
Merge pull request EOSIO#348 from EOSIO/access-control-347
Browse files Browse the repository at this point in the history
Add Access-Control-Allow-Origin to http
  • Loading branch information
bytemaster authored Sep 5, 2017
2 parents d98f57a + 914c526 commit 24a21e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Docker/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions plugins/http_plugin/http_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ namespace eos {
//asio::io_service http_ios;
map<string,url_handler> url_handlers;
optional<tcp::endpoint> listen_endpoint;
string access_control_allow_origin;

websocket_server_type server;
};
Expand All @@ -91,6 +92,8 @@ namespace eos {
cfg.add_options()
("http-server-endpoint", bpo::value<string>()->default_value("127.0.0.1:8888"),
"The local IP and port to listen for incoming http connections.")
("access-control-allow-origin", bpo::value<string>(),
"Specify the Access-Control-Allow-Origin to be returned on each request.")
;
}

Expand All @@ -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<string>();
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());
}
Expand All @@ -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);
Expand Down

0 comments on commit 24a21e6

Please sign in to comment.