2025-04-12 20:06:56 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <pistache/http.h>
|
|
|
|
|
|
2025-04-12 23:50:45 +01:00
|
|
|
// Giga hack, but we need it cuz the API is quite awkward and incomplete
|
|
|
|
|
#define private public
|
|
|
|
|
#include <pistache/client.h>
|
|
|
|
|
#undef private
|
|
|
|
|
|
2025-04-12 20:06:56 +01:00
|
|
|
class CServerHandler : public Pistache::Http::Handler {
|
|
|
|
|
|
|
|
|
|
HTTP_PROTOTYPE(CServerHandler)
|
|
|
|
|
|
2025-04-15 15:26:08 +01:00
|
|
|
void init();
|
|
|
|
|
void finish();
|
|
|
|
|
|
2025-04-12 20:06:56 +01:00
|
|
|
void onRequest(const Pistache::Http::Request& req, Pistache::Http::ResponseWriter response);
|
|
|
|
|
|
|
|
|
|
void onTimeout(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter response);
|
|
|
|
|
|
|
|
|
|
private:
|
2025-04-15 01:34:57 +01:00
|
|
|
void serveStop(const Pistache::Http::Request& req, Pistache::Http::ResponseWriter& response, int difficulty);
|
2025-04-13 16:08:51 +01:00
|
|
|
void proxyPass(const Pistache::Http::Request& req, Pistache::Http::ResponseWriter& response);
|
|
|
|
|
void challengeSubmitted(const Pistache::Http::Request& req, Pistache::Http::ResponseWriter& response);
|
|
|
|
|
std::string fingerprintForRequest(const Pistache::Http::Request& req);
|
2025-04-15 14:37:54 +01:00
|
|
|
std::string ipForRequest(const Pistache::Http::Request& req);
|
2025-04-12 20:06:56 +01:00
|
|
|
|
2025-04-13 16:53:17 +01:00
|
|
|
bool isResourceCheckpoint(const std::string_view& res);
|
|
|
|
|
|
2025-04-12 20:06:56 +01:00
|
|
|
struct SChallengeResponse {
|
|
|
|
|
std::string challenge;
|
|
|
|
|
unsigned long int solution = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct STokenResponse {
|
|
|
|
|
bool success = false;
|
|
|
|
|
std::string token = "";
|
|
|
|
|
std::string error = "";
|
|
|
|
|
};
|
2025-04-15 15:26:08 +01:00
|
|
|
|
|
|
|
|
Pistache::Http::Experimental::Client* m_client = nullptr;
|
2025-04-12 20:06:56 +01:00
|
|
|
};
|