diff options
| author | Stefan Boberg <[email protected]> | 2025-12-11 09:34:24 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-12-11 09:34:24 +0100 |
| commit | 3de9a65cd990f2a4f5395b7e2a094471633eb98b (patch) | |
| tree | f1640a32fd2b68a8f1b6f77f5ba5c4cbf959cb0b /src/zenhttp/include | |
| parent | 5.7.14-pre3 (diff) | |
| download | zen-3de9a65cd990f2a4f5395b7e2a094471633eb98b.tar.xz zen-3de9a65cd990f2a4f5395b7e2a094471633eb98b.zip | |
HTTP server API changes for improved extensibility (#684)
* refactored `HttpServer` so all subclass member functions are proctected, to make it easier to extend base functionality
* added API service, can be used to enumerate registered endpoints (at `/api`). Currently only very basic information is provided
Diffstat (limited to 'src/zenhttp/include')
| -rw-r--r-- | src/zenhttp/include/zenhttp/httpapiservice.h | 21 | ||||
| -rw-r--r-- | src/zenhttp/include/zenhttp/httpserver.h | 21 |
2 files changed, 37 insertions, 5 deletions
diff --git a/src/zenhttp/include/zenhttp/httpapiservice.h b/src/zenhttp/include/zenhttp/httpapiservice.h new file mode 100644 index 000000000..0270973bf --- /dev/null +++ b/src/zenhttp/include/zenhttp/httpapiservice.h @@ -0,0 +1,21 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include <zenhttp/httpserver.h> + +namespace zen { + +class HttpApiService : public HttpService +{ +public: + HttpApiService(HttpServer& Server); + ~HttpApiService() override; + + const char* BaseUri() const override; + void HandleRequest(HttpServerRequest& HttpServiceRequest) override; + +private: + HttpServer& m_Server; + HttpRequestRouter m_Router; +}; + +} // namespace zen diff --git a/src/zenhttp/include/zenhttp/httpserver.h b/src/zenhttp/include/zenhttp/httpserver.h index f95ec51d2..9e5c41ab7 100644 --- a/src/zenhttp/include/zenhttp/httpserver.h +++ b/src/zenhttp/include/zenhttp/httpserver.h @@ -175,11 +175,22 @@ private: class HttpServer : public RefCounted { public: - virtual void RegisterService(HttpService& Service) = 0; - virtual int Initialize(int BasePort, std::filesystem::path DataDir) = 0; - virtual void Run(bool IsInteractiveSession) = 0; - virtual void RequestExit() = 0; - virtual void Close() = 0; + void RegisterService(HttpService& Service); + void EnumerateServices(std::function<void(HttpService&)>&& Callback); + + int Initialize(int BasePort, std::filesystem::path DataDir); + void Run(bool IsInteractiveSession); + void RequestExit(); + void Close(); + +private: + std::vector<HttpService*> m_KnownServices; + + virtual void OnRegisterService(HttpService& Service) = 0; + virtual int OnInitialize(int BasePort, std::filesystem::path DataDir) = 0; + virtual void OnRun(bool IsInteractiveSession) = 0; + virtual void OnRequestExit() = 0; + virtual void OnClose() = 0; }; struct HttpServerPluginConfig |