Restored API.
This commit is contained in:
parent
e39ddeeea2
commit
f8f9d6c0ef
16 changed files with 272 additions and 352 deletions
|
@ -25,10 +25,12 @@
|
|||
|
||||
#include "api/requests/HttpApiRequest.h"
|
||||
#include "base/net/http/HttpRequest.h"
|
||||
#include "rapidjson/error/en.h"
|
||||
|
||||
|
||||
xmrig::HttpApiRequest::HttpApiRequest(const HttpRequest &req, bool restricted) :
|
||||
ApiRequest(SOURCE_HTTP, restricted),
|
||||
m_parsed(false),
|
||||
m_req(req),
|
||||
m_res(req.id()),
|
||||
m_url(req.url.c_str())
|
||||
|
@ -36,20 +38,39 @@ xmrig::HttpApiRequest::HttpApiRequest(const HttpRequest &req, bool restricted) :
|
|||
}
|
||||
|
||||
|
||||
const rapidjson::Value &xmrig::HttpApiRequest::json() const
|
||||
{
|
||||
return m_body;
|
||||
}
|
||||
|
||||
|
||||
xmrig::IApiRequest::Method xmrig::HttpApiRequest::method() const
|
||||
{
|
||||
return static_cast<IApiRequest::Method>(m_req.method);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::HttpApiRequest::accept()
|
||||
{
|
||||
using namespace rapidjson;
|
||||
|
||||
ApiRequest::accept();
|
||||
|
||||
if (!m_parsed && !m_req.body.empty()) {
|
||||
m_parsed = true;
|
||||
m_body.Parse<kParseCommentsFlag | kParseTrailingCommasFlag>(m_req.body.c_str());
|
||||
|
||||
if (m_body.HasParseError()) {
|
||||
reply().AddMember("error", StringRef(GetParseError_En(m_body.GetParseError())), doc().GetAllocator());;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::HttpApiRequest::done(int status)
|
||||
{
|
||||
ApiRequest::done(status);
|
||||
|
||||
if (status >= 400) {
|
||||
reply().AddMember("status", status, doc().GetAllocator());
|
||||
}
|
||||
|
||||
m_res.setStatus(status);
|
||||
m_res.end();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue