Added HttpClient class.
This commit is contained in:
parent
35d868fb48
commit
241383068c
17 changed files with 421 additions and 153 deletions
|
@ -28,7 +28,7 @@
|
|||
#include "api/Httpd.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/net/http/HttpApiResponse.h"
|
||||
#include "base/net/http/HttpRequest.h"
|
||||
#include "base/net/http/HttpData.h"
|
||||
#include "base/net/http/HttpServer.h"
|
||||
#include "base/net/tools/TcpServer.h"
|
||||
#include "core/config/Config.h"
|
||||
|
@ -128,49 +128,49 @@ void xmrig::Httpd::onConfigChanged(Config *config, Config *previousConfig)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::Httpd::onHttpRequest(const HttpRequest &req)
|
||||
void xmrig::Httpd::onHttpData(const HttpData &data)
|
||||
{
|
||||
if (req.method == HTTP_OPTIONS) {
|
||||
return HttpApiResponse(req.id()).end();
|
||||
if (data.method == HTTP_OPTIONS) {
|
||||
return HttpApiResponse(data.id()).end();
|
||||
}
|
||||
|
||||
if (req.method == HTTP_GET && req.url == "/favicon.ico") {
|
||||
if (data.method == HTTP_GET && data.url == "/favicon.ico") {
|
||||
# ifdef _WIN32
|
||||
if (favicon != nullptr) {
|
||||
HttpResponse response(req.id());
|
||||
HttpResponse response(data.id());
|
||||
response.setHeader("Content-Type", "image/x-icon");
|
||||
|
||||
return response.end(favicon, faviconSize);
|
||||
}
|
||||
# endif
|
||||
|
||||
return HttpResponse(req.id(), 404).end();
|
||||
return HttpResponse(data.id(), 404).end();
|
||||
}
|
||||
|
||||
if (req.method > 4) {
|
||||
return HttpApiResponse(req.id(), HTTP_STATUS_METHOD_NOT_ALLOWED).end();
|
||||
if (data.method > 4) {
|
||||
return HttpApiResponse(data.id(), HTTP_STATUS_METHOD_NOT_ALLOWED).end();
|
||||
}
|
||||
|
||||
const int status = auth(req);
|
||||
const int status = auth(data);
|
||||
if (status != HTTP_STATUS_OK) {
|
||||
return HttpApiResponse(req.id(), status).end();
|
||||
return HttpApiResponse(data.id(), status).end();
|
||||
}
|
||||
|
||||
if (req.method != HTTP_GET) {
|
||||
if (data.method != HTTP_GET) {
|
||||
if (m_base->config()->http().isRestricted()) {
|
||||
return HttpApiResponse(req.id(), HTTP_STATUS_FORBIDDEN).end();
|
||||
return HttpApiResponse(data.id(), HTTP_STATUS_FORBIDDEN).end();
|
||||
}
|
||||
|
||||
if (!req.headers.count(kContentType) || req.headers.at(kContentType) != "application/json") {
|
||||
return HttpApiResponse(req.id(), HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE).end();
|
||||
if (!data.headers.count(kContentType) || data.headers.at(kContentType) != "application/json") {
|
||||
return HttpApiResponse(data.id(), HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE).end();
|
||||
}
|
||||
}
|
||||
|
||||
m_base->api()->request(req);
|
||||
m_base->api()->request(data);
|
||||
}
|
||||
|
||||
|
||||
int xmrig::Httpd::auth(const HttpRequest &req) const
|
||||
int xmrig::Httpd::auth(const HttpData &req) const
|
||||
{
|
||||
const Http &config = m_base->config()->http();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue