diff options
| author | Stefan Boberg <[email protected]> | 2023-06-30 10:55:49 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2023-06-30 10:55:49 +0200 |
| commit | 912cd60c4cdfd6e0253ee1b9ed1abade09ac8b7c (patch) | |
| tree | ef0994084304dd5ce1fdd42621e36a9b34b191f7 /src/zenhttp/include | |
| parent | added zen::ChunkResolver (diff) | |
| download | zen-912cd60c4cdfd6e0253ee1b9ed1abade09ac8b7c.tar.xz zen-912cd60c4cdfd6e0253ee1b9ed1abade09ac8b7c.zip | |
various zenhttp fixes from sb/proto
* Made HttpHealthService use locks to serialize access to state
* Added ToString(HttpResponseCode HttpCode)
* Added support for JS source maps
* Moved IHttpStatsProvider/IHttpStatsService
* Enabled enumeration of stats providers
* Disabled build of HttpTestingService unless ZEN_WITH_TESTS is defined
Diffstat (limited to 'src/zenhttp/include')
| -rw-r--r-- | src/zenhttp/include/zenhttp/diagsvcs.h | 16 | ||||
| -rw-r--r-- | src/zenhttp/include/zenhttp/httpcommon.h | 4 | ||||
| -rw-r--r-- | src/zenhttp/include/zenhttp/httpserver.h | 13 | ||||
| -rw-r--r-- | src/zenhttp/include/zenhttp/httpstats.h | 11 | ||||
| -rw-r--r-- | src/zenhttp/include/zenhttp/httptest.h | 4 |
5 files changed, 35 insertions, 13 deletions
diff --git a/src/zenhttp/include/zenhttp/diagsvcs.h b/src/zenhttp/include/zenhttp/diagsvcs.h index bd03f8023..8cc869c83 100644 --- a/src/zenhttp/include/zenhttp/diagsvcs.h +++ b/src/zenhttp/include/zenhttp/diagsvcs.h @@ -11,10 +11,15 @@ namespace zen { +/** HTTP test endpoint + + This is intended to be used to exercise basic HTTP communication infrastructure + which is useful for benchmarking performance of the server code and when evaluating + network performance / diagnosing connectivity issues + + */ class HttpTestService : public HttpService { - uint32_t LogPoint = 0; - public: HttpTestService() {} ~HttpTestService() = default; @@ -30,8 +35,6 @@ public: if (Uri == "hello"sv) { Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, u8"hello world!"sv); - - // OutputLogMessageInternal(&LogPoint, 0, 0); } else if (Uri == "1K"sv) { @@ -92,6 +95,10 @@ struct HealthServiceInfo std::string BuildVersion; }; +/** Health monitoring endpoint + + Thji + */ class HttpHealthService : public HttpService { public: @@ -105,6 +112,7 @@ public: private: HttpRequestRouter m_Router; + RwLock m_InfoLock; HealthServiceInfo m_HealthInfo; }; diff --git a/src/zenhttp/include/zenhttp/httpcommon.h b/src/zenhttp/include/zenhttp/httpcommon.h index fb0d128a2..bc18549c9 100644 --- a/src/zenhttp/include/zenhttp/httpcommon.h +++ b/src/zenhttp/include/zenhttp/httpcommon.h @@ -179,9 +179,11 @@ IsHttpSuccessCode(int HttpCode) noexcept } [[nodiscard]] inline bool -IsHttpSuccessCode(HttpResponseCode HttpCode) +IsHttpSuccessCode(HttpResponseCode HttpCode) noexcept { return IsHttpSuccessCode(int(HttpCode)); } +std::string_view ToString(HttpResponseCode HttpCode); + } // namespace zen diff --git a/src/zenhttp/include/zenhttp/httpserver.h b/src/zenhttp/include/zenhttp/httpserver.h index dd66b1fe7..d1a562ee4 100644 --- a/src/zenhttp/include/zenhttp/httpserver.h +++ b/src/zenhttp/include/zenhttp/httpserver.h @@ -23,6 +23,8 @@ namespace zen { +class CbPackage; + /** HTTP Server Request */ class HttpServerRequest @@ -311,6 +313,17 @@ private: bool HandlePackageOffers(HttpService& Service, HttpServerRequest& Request, Ref<IHttpPackageHandler>& PackageHandlerRef); +struct IHttpStatsProvider +{ + virtual void HandleStatsRequest(HttpServerRequest& Request) = 0; +}; + +struct IHttpStatsService +{ + virtual void RegisterHandler(std::string_view Id, IHttpStatsProvider& Provider) = 0; + virtual void UnregisterHandler(std::string_view Id, IHttpStatsProvider& Provider) = 0; +}; + void http_forcelink(); // internal } // namespace zen diff --git a/src/zenhttp/include/zenhttp/httpstats.h b/src/zenhttp/include/zenhttp/httpstats.h index 732815a9a..4a1cdcb20 100644 --- a/src/zenhttp/include/zenhttp/httpstats.h +++ b/src/zenhttp/include/zenhttp/httpstats.h @@ -9,12 +9,7 @@ namespace zen { -struct IHttpStatsProvider -{ - virtual void HandleStatsRequest(HttpServerRequest& Request) = 0; -}; - -class HttpStatsService : public HttpService +class HttpStatsService : public HttpService, public IHttpStatsService { public: HttpStatsService(); @@ -22,8 +17,8 @@ public: virtual const char* BaseUri() const override; virtual void HandleRequest(HttpServerRequest& Request) override; - void RegisterHandler(std::string_view Id, IHttpStatsProvider& Provider); - void UnregisterHandler(std::string_view Id, IHttpStatsProvider& Provider); + virtual void RegisterHandler(std::string_view Id, IHttpStatsProvider& Provider) override; + virtual void UnregisterHandler(std::string_view Id, IHttpStatsProvider& Provider) override; private: spdlog::logger& m_Log; diff --git a/src/zenhttp/include/zenhttp/httptest.h b/src/zenhttp/include/zenhttp/httptest.h index 57d2d63f3..74db69785 100644 --- a/src/zenhttp/include/zenhttp/httptest.h +++ b/src/zenhttp/include/zenhttp/httptest.h @@ -9,6 +9,8 @@ #include <atomic> +#if ZEN_WITH_TESTS + namespace zen { /** @@ -53,3 +55,5 @@ private: }; } // namespace zen + +#endif |