JSON API accessible via HTTP GET method

This is useful in cases where the client cannot use POST method.
/jsonApiServer/shutdown now reply before shutting down the core.
This commit is contained in:
Gioacchino Mazzurco 2018-09-12 23:40:34 +02:00
parent 3d476f689f
commit 148e46346d
No known key found for this signature in database
GPG key ID: A1FBCA3872E87051
2 changed files with 39 additions and 5 deletions

View file

@ -36,7 +36,13 @@
nullptr, 0, \
RsGenericSerializer::SERIALIZATION_FLAG_YIELDING ); \
RsJson& jReq(cReq.mJson); \
jReq.Parse(reinterpret_cast<const char*>(body.data()), body.size()); \
if(session->get_request()->get_method() == "GET") \
{ \
const std::string jrqp(session->get_request()->get_query_parameter("jsonData")); \
jReq.Parse(jrqp.c_str(), jrqp.size()); \
} \
else \
jReq.Parse(reinterpret_cast<const char*>(body.data()), body.size()); \
\
RsGenericSerializer::SerializeContext cAns; \
RsJson& jAns(cAns.mJson); \
@ -87,8 +93,15 @@ JsonApiServer::JsonApiServer(
registerHandler("/jsonApiServer/shutdown",
[this](const std::shared_ptr<rb::Session> session)
{
session->close(rb::OK);
shutdown();
size_t reqSize = session->get_request()->get_header("Content-Length", 0);
session->fetch( reqSize, [this](
const std::shared_ptr<rb::Session> session,
const rb::Bytes& body )
{
INITIALIZE_API_CALL_JSON_CONTEXT;
DEFAULT_API_CALL_JSON_RETURN(rb::OK);
shutdown();
} );
});
registerHandler("/jsonApiServer/version",