Adding Access-Control-Allow-Origin header to allow browsers to hit RPCs.
This commit is contained in:
parent
6f68d923a0
commit
f5c0f6dffb
2 changed files with 5 additions and 0 deletions
|
@ -1226,6 +1226,10 @@ TEST (rpc, version)
|
|||
ASSERT_EQ (boost::network::http::server <rai::rpc>::response::ok, static_cast <uint16_t> (boost::network::http::status (response1.second)));
|
||||
ASSERT_EQ ("2", response1.first.get <std::string> ("store_version"));
|
||||
ASSERT_EQ (boost::str (boost::format ("RaiBlocks %1%.%2%.%3%") % RAIBLOCKS_VERSION_MAJOR % RAIBLOCKS_VERSION_MINOR % RAIBLOCKS_VERSION_PATCH), response1.first.get <std::string> ("node_vendor"));
|
||||
auto headers (response1.second.headers ());
|
||||
auto access_control (std::find_if (headers.begin (), headers.end (), [] (decltype (*headers.begin ()) & header_a) { return header_a.first == "Access-Control-Allow-Origin"; }));
|
||||
ASSERT_NE (headers.end (), access_control);
|
||||
ASSERT_EQ ("*", access_control->second);
|
||||
rpc.stop();
|
||||
thread1.join ();
|
||||
}
|
||||
|
|
|
@ -105,6 +105,7 @@ void rai::rpc::send_response (boost::network::http::async_server <rai::rpc>::con
|
|||
response->headers.push_back (boost::network::http::response_header_narrow {"content-type", "application/json"});
|
||||
response->content = ostream.str ();
|
||||
response->headers.push_back (boost::network::http::response_header_narrow {"content-length", std::to_string (response->content.size ())});
|
||||
response->headers.push_back (boost::network::http::response_header_narrow {"Access-Control-Allow-Origin", "*"});
|
||||
connection->write (response->to_buffers (), [response, connection] (boost::system::error_code const & ec)
|
||||
{
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue