UniSet @VERSION@
HTTPHandler.h
1/*
2 * Copyright (c) 2026 Pavel Vainerman.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation, version 2.1.
7 */
8// -------------------------------------------------------------------------
9#ifndef LauncherHTTPHandler_H_
10#define LauncherHTTPHandler_H_
11// -------------------------------------------------------------------------
12#include <memory>
13#include <Poco/Net/HTTPServer.h>
14#include <Poco/Net/HTTPRequestHandler.h>
15#include <Poco/Net/HTTPRequestHandlerFactory.h>
16#include <Poco/Net/HTTPServerRequest.h>
17#include <Poco/Net/HTTPServerResponse.h>
18#include "ProcessManager.h"
19// -------------------------------------------------------------------------
20namespace uniset
21{
32 class LauncherHTTPHandler : public Poco::Net::HTTPRequestHandler
33 {
34 public:
36
37 void handleRequest(Poco::Net::HTTPServerRequest& request,
38 Poco::Net::HTTPServerResponse& response) override;
39
40 private:
41 void handleStatus(Poco::Net::HTTPServerResponse& response);
42 void handleProcess(const std::string& name,
43 Poco::Net::HTTPServerResponse& response);
44 void handleRestart(const std::string& name,
45 Poco::Net::HTTPServerResponse& response);
46 void handleHealth(Poco::Net::HTTPServerResponse& response);
47 void handleGroups(Poco::Net::HTTPServerResponse& response);
48
49 void sendJSON(Poco::Net::HTTPServerResponse& response,
50 const std::string& json,
51 Poco::Net::HTTPResponse::HTTPStatus status =
52 Poco::Net::HTTPResponse::HTTP_OK);
53
54 void sendError(Poco::Net::HTTPServerResponse& response,
55 Poco::Net::HTTPResponse::HTTPStatus status,
56 const std::string& message);
57
58 std::string processToJSON(const ProcessInfo& proc);
59 std::string groupToJSON(const ProcessGroup& group);
60
61 ProcessManager& pm_;
62 };
63
67 class LauncherHTTPHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory
68 {
69 public:
71
72 Poco::Net::HTTPRequestHandler* createRequestHandler(
73 const Poco::Net::HTTPServerRequest& request) override;
74
75 private:
76 ProcessManager& pm_;
77 };
78
79} // end of namespace uniset
80// -------------------------------------------------------------------------
81#endif // LauncherHTTPHandler_H_
82// -------------------------------------------------------------------------
Definition HTTPHandler.h:68
Definition HTTPHandler.h:33
Definition ProcessManager.h:51
Definition AccessConfig.h:30
Definition ProcessInfo.h:113
Definition ProcessInfo.h:66