Special handle for favicon.ico

This commit is contained in:
XMRig 2019-04-01 11:50:28 +07:00
parent 4457089502
commit 3b91817caf
4 changed files with 33 additions and 4 deletions

View file

@ -1,7 +1,7 @@
#include <windows.h> #include <windows.h>
#include "../src/version.h" #include "../src/version.h"
IDI_ICON1 ICON DISCARDABLE "app.ico" 101 ICON "app.ico"
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION APP_VER_MAJOR,APP_VER_MINOR,APP_VER_PATCH,0 FILEVERSION APP_VER_MAJOR,APP_VER_MINOR,APP_VER_PATCH,0

View file

@ -40,6 +40,11 @@ namespace xmrig {
static const char *kAuthorization = "authorization"; static const char *kAuthorization = "authorization";
static const char *kContentType = "content-type"; static const char *kContentType = "content-type";
#ifdef _WIN32
static const char *favicon = nullptr;
static size_t faviconSize = 0;
#endif
} // namespace xmrig } // namespace xmrig
@ -85,6 +90,17 @@ bool xmrig::Httpd::start()
m_port = static_cast<uint16_t>(rc); m_port = static_cast<uint16_t>(rc);
# ifdef _WIN32
HRSRC src = FindResource(nullptr, MAKEINTRESOURCE(1), RT_ICON);
if (src != nullptr) {
HGLOBAL res = LoadResource(nullptr, src);
if (res != nullptr) {
favicon = static_cast<const char *>(LockResource(res));
faviconSize = SizeofResource(nullptr, src);
}
}
# endif
return true; return true;
} }
@ -118,6 +134,19 @@ void xmrig::Httpd::onHttpRequest(const HttpRequest &req)
return HttpApiResponse(req.id()).end(); return HttpApiResponse(req.id()).end();
} }
if (req.method == HTTP_GET && req.url == "/favicon.ico") {
# ifdef _WIN32
if (favicon != nullptr) {
HttpResponse response(req.id());
response.setHeader("Content-Type", "image/x-icon");
return response.end(favicon, faviconSize);
}
# endif
return HttpResponse(req.id(), 404).end();
}
if (req.method > 4) { if (req.method > 4) {
return HttpApiResponse(req.id(), HTTP_STATUS_METHOD_NOT_ALLOWED).end(); return HttpApiResponse(req.id(), HTTP_STATUS_METHOD_NOT_ALLOWED).end();
} }

View file

@ -43,9 +43,9 @@ static const char *kUserAgent = "user-agent";
} // namespace xmrig } // namespace xmrig
xmrig::HttpResponse::HttpResponse(uint64_t id) : xmrig::HttpResponse::HttpResponse(uint64_t id, int statusCode) :
m_id(id), m_id(id),
m_statusCode(HTTP_STATUS_OK) m_statusCode(statusCode)
{ {
} }

View file

@ -38,7 +38,7 @@ namespace xmrig {
class HttpResponse class HttpResponse
{ {
public: public:
HttpResponse(uint64_t id); HttpResponse(uint64_t id, int statusCode = 200);
inline int statusCode() const { return m_statusCode; } inline int statusCode() const { return m_statusCode; }
inline void setHeader(const std::string &key, const std::string &value) { m_headers.insert({ key, value }); } inline void setHeader(const std::string &key, const std::string &value) { m_headers.insert({ key, value }); }