diff options
| author | Stefan Boberg <[email protected]> | 2026-02-25 10:15:41 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-02-25 10:15:41 +0100 |
| commit | 241e4faf64be83711dc509ad8a25ff4e8ae95c12 (patch) | |
| tree | 36d4168f89999942060d6c07e41c84a84512b3e9 /src/zenhttp/include | |
| parent | Fix zencore bugs and propagate content type through IoBufferBuilder (#783) (diff) | |
| download | zen-241e4faf64be83711dc509ad8a25ff4e8ae95c12.tar.xz zen-241e4faf64be83711dc509ad8a25ff4e8ae95c12.zip | |
HttpService/Frontend improvements (#782)
- zenhttp: added `GetServiceUri()`/`GetExternalHost()`
- enables code to quickly generate an externally reachable URI for a given service
- frontend: improved Uri handling (better defaults)
- added support for 404 page (to make it easier to find a good URL)
Diffstat (limited to 'src/zenhttp/include')
| -rw-r--r-- | src/zenhttp/include/zenhttp/httpserver.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/zenhttp/include/zenhttp/httpserver.h b/src/zenhttp/include/zenhttp/httpserver.h index 350532126..00cbc6c14 100644 --- a/src/zenhttp/include/zenhttp/httpserver.h +++ b/src/zenhttp/include/zenhttp/httpserver.h @@ -219,8 +219,21 @@ public: void RequestExit(); void Close(); + /** Returns a canonical http:// URI for the given service, using the external + * IP and the port the server is actually listening on. Only valid + * after Initialize() has returned successfully. + */ + std::string GetServiceUri(const HttpService* Service) const; + + /** Returns the external host string (IP or hostname) determined during Initialize(). + * Only valid after Initialize() has returned successfully. + */ + std::string_view GetExternalHost() const { return m_ExternalHost; } + private: std::vector<HttpService*> m_KnownServices; + int m_EffectivePort = 0; + std::string m_ExternalHost; virtual void OnRegisterService(HttpService& Service) = 0; virtual int OnInitialize(int BasePort, std::filesystem::path DataDir) = 0; @@ -228,6 +241,9 @@ private: virtual void OnRun(bool IsInteractiveSession) = 0; virtual void OnRequestExit() = 0; virtual void OnClose() = 0; + +protected: + virtual std::string OnGetExternalHost() const; }; struct HttpServerPluginConfig |