Holding lifetime of response open until write has finished.

This commit is contained in:
clemahieu 2017-02-10 19:45:48 -06:00
commit fabe60d399
2 changed files with 9 additions and 7 deletions

View file

@ -1635,16 +1635,17 @@ void rai::rpc_connection::parse_connection ()
auto version (this_l->request.version);
auto response_handler ([this_l, version] (boost::property_tree::ptree const & tree_a)
{
beast::http::response <beast::http::string_body> res;
std::stringstream ostream;
boost::property_tree::write_json (ostream, tree_a);
ostream.flush ();
auto body (ostream.str ());
res.fields.insert ("content-type", "application/json");
res.fields.insert ("Access-Control-Allow-Origin", "*");
res.status = 200;
res.body = body;
res.version = version;
beast::http::async_write (this_l->socket, res, [this_l] (boost::system::error_code const & ec)
this_l->res.fields.insert ("content-type", "application/json");
this_l->res.fields.insert ("Access-Control-Allow-Origin", "*");
this_l->res.status = 200;
this_l->res.body = body;
this_l->res.version = version;
beast::http::prepare (this_l->res);
beast::http::async_write (this_l->socket, this_l->res, [this_l] (boost::system::error_code const & ec)
{
});
});

View file

@ -64,6 +64,7 @@ public:
boost::asio::ip::tcp::socket socket;
beast::streambuf buffer;
beast::http::request <beast::http::string_body> request;
beast::http::response <beast::http::string_body> res;
};
class payment_observer : public std::enable_shared_from_this <rai::payment_observer>
{