13 #ifndef mitkRestServer_h
14 #define mitkRestServer_h
28 #include <unordered_map>
40 class DataStorageBridge;
41 class HealthController;
42 class DataStorageController;
43 class SwaggerController;
44 class RenderingController;
45 class RenderWindowBridge;
103 void RecordRequest(
const std::string& endpoint,
const std::string& method,
104 int responseCode,
const std::string& clientIP);
105 void RegisterRoutes();
106 void ServerThreadFunc();
110 void SyncDispatcherToController();
121 bool CheckClientAccess(
const httplib::Request& req, httplib::Response& res);
132 bool CheckRateLimit(
const httplib::Request& req, httplib::Response& res);
144 bool CheckAuthentication(
const httplib::Request& req, httplib::Response& res);
147 std::unique_ptr<httplib::Server> m_Server;
148 std::unique_ptr<std::thread> m_ServerThread;
151 std::unique_ptr<DataStorageBridge> m_Bridge;
152 std::unique_ptr<RenderWindowBridge> m_RenderWindowBridge;
153 std::unique_ptr<HealthController> m_HealthController;
154 std::unique_ptr<DataStorageController> m_DataStorageController;
155 std::unique_ptr<SwaggerController> m_SwaggerController;
156 std::unique_ptr<RenderingController> m_RenderingController;
160 mutable std::mutex m_Mutex;
162 std::optional<RestServerConfig> m_RunningConfig;
163 std::atomic<bool> m_Running{
false};
164 std::optional<std::string> m_LastError;
167 std::set<std::string> m_ClientIPs;
170 std::deque<RequestInfo> m_RequestLog;
171 std::optional<unsigned int> m_LogLimit;
172 uint64_t m_RequestLogVersion{0};
175 std::string m_TempDirectory;
178 std::optional<std::chrono::steady_clock::time_point> m_StartTime;
181 std::unordered_map<std::string, std::deque<std::chrono::steady_clock::time_point>> m_RateLimitMap;
182 uint64_t m_RateLimitCheckCount{0};
191 bool SetupTempDirectory();
202 static void CleanupTempDirectory(
const std::string& tempDir);
#define MITKRESTAPI_EXPORT
Abstract data management class that organizes DataNode objects in a directed acyclic graph.
Bridge between the REST API server and the Qt/render-window layer.
HTTP REST server implementation.
std::optional< std::string > GetLastError() const override
Get the last error message.
std::optional< unsigned int > GetLogLimit() const override
Get the current request log limit.
DataStorage::Pointer GetDataStorage() const override
Get the currently connected DataStorage.
bool Start() override
Start the REST server with the pending configuration.
void ClearRequestLog() override
Clear all logged requests.
std::optional< std::string > GetServerUrl() const override
Get the full URL where the server is listening.
std::vector< RequestInfo > GetRequestLog() const override
Get all logged requests.
std::optional< RequestInfo > GetLastRequestInfo() const override
Get information about the last request processed.
RenderWindowBridge * GetRenderWindowBridge() override
Return the server-owned RenderWindowBridge.
void SetLogLimit(std::optional< unsigned int > limit) override
Set the request log limit.
RestServerConfig GetPendingConfig() const override
Get the pending server configuration.
RestServer(const RestServer &)=delete
std::vector< std::string > GetClientIPs() const override
Get the list of client IP addresses that have sent requests.
void SetConfig(const RestServerConfig &config) override
Set the pending server configuration.
bool IsRunning() const override
Check if the server is currently running.
void SetDispatcher(StorageThreadDispatcherBase *dispatcher)
Set the thread dispatcher for DataStorage operations.
std::optional< int64_t > GetUptimeSeconds() const override
Get the server uptime in seconds.
RestServer(RestServer &&)=delete
RestServer & operator=(const RestServer &)=delete
void SetDataStorage(DataStorage *dataStorage) override
Set the DataStorage for REST API operations.
uint64_t GetRequestLogVersion() const override
Get the request log version counter.
void Stop() override
Stop the REST server.
RestServer & operator=(RestServer &&)=delete
std::optional< RestServerConfig > GetRunningConfig() const override
Get the configuration the server is currently running with.
Abstract base class for dispatching tasks to the thread that owns DataStorage.
A weak pointer that observes an itk::Object without preventing its deletion.
Find image slices visible on a given plane.
Service interface for the REST API server.
Configuration parameters for the REST API server.