From bf9abfda914d2619c30df3ab6c7904fb87c93901 Mon Sep 17 00:00:00 2001 From: Per Larsson Date: Fri, 1 Oct 2021 15:45:57 +0200 Subject: Added simple stats HTML dashboard with route /dashboard. --- zenhttp/httpserver.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'zenhttp/httpserver.cpp') diff --git a/zenhttp/httpserver.cpp b/zenhttp/httpserver.cpp index 8e5d61877..cfd1463ba 100644 --- a/zenhttp/httpserver.cpp +++ b/zenhttp/httpserver.cpp @@ -58,6 +58,9 @@ MapContentTypeToString(HttpContentType ContentType) case HttpContentType::kYAML: return "text/yaml"sv; + + case HttpContentType::kHTML: + return "text/html"sv; } } -- cgit v1.2.3 From 645ce60a493e7c1af24f245c56b6c3fca3e3f2b2 Mon Sep 17 00:00:00 2001 From: Per Larsson Date: Sun, 3 Oct 2021 09:38:09 +0200 Subject: Fixed missing content type. --- zenhttp/httpserver.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'zenhttp/httpserver.cpp') diff --git a/zenhttp/httpserver.cpp b/zenhttp/httpserver.cpp index cfd1463ba..3a746fd51 100644 --- a/zenhttp/httpserver.cpp +++ b/zenhttp/httpserver.cpp @@ -74,6 +74,7 @@ static constinit uint32_t HashCompactBinary = HashStringDjb2("application/x-u static constinit uint32_t HashCompactBinaryPackage = HashStringDjb2("application/x-ue-cbpkg"sv); static constinit uint32_t HashCompactBinaryPackageOffer = HashStringDjb2("application/x-ue-offer"sv); static constinit uint32_t HashCompressedBinary = HashStringDjb2("application/x-ue-comp"sv); +static constinit uint32_t HashHtml = HashStringDjb2("text/html"sv); std::once_flag InitContentTypeLookup; @@ -88,7 +89,8 @@ struct HashedTypeEntry {HashJson, HttpContentType::kJSON}, {HashYaml, HttpContentType::kYAML}, {HashText, HttpContentType::kText}, - {HashCompressedBinary, HttpContentType::kCompressedBinary}}; + {HashCompressedBinary, HttpContentType::kCompressedBinary}, + {HashHtml, HttpContentType::kHTML}}; HttpContentType ParseContentTypeImpl(const std::string_view& ContentTypeString) -- cgit v1.2.3 From a3bb0e6a98259cb674266816c0ee9726171c0097 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Sun, 3 Oct 2021 17:00:19 +0200 Subject: http: Added support for specifying response content-type by means of suffixes (.json/.yaml etc) If a suffix is present then we'll use that instead of any Accept: header value --- zenhttp/httpserver.cpp | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'zenhttp/httpserver.cpp') diff --git a/zenhttp/httpserver.cpp b/zenhttp/httpserver.cpp index cfd1463ba..58f6858a8 100644 --- a/zenhttp/httpserver.cpp +++ b/zenhttp/httpserver.cpp @@ -67,13 +67,15 @@ MapContentTypeToString(HttpContentType ContentType) ////////////////////////////////////////////////////////////////////////// static constinit uint32_t HashBinary = HashStringDjb2("application/octet-stream"sv); -static constinit uint32_t HashJson = HashStringDjb2("application/json"sv); -static constinit uint32_t HashYaml = HashStringDjb2("text/yaml"sv); +static constinit uint32_t HashApplicationJson = HashStringDjb2("application/json"sv); +static constinit uint32_t HashApplicationYaml = HashStringDjb2("text/yaml"sv); static constinit uint32_t HashText = HashStringDjb2("text/plain"sv); static constinit uint32_t HashCompactBinary = HashStringDjb2("application/x-ue-cb"sv); static constinit uint32_t HashCompactBinaryPackage = HashStringDjb2("application/x-ue-cbpkg"sv); static constinit uint32_t HashCompactBinaryPackageOffer = HashStringDjb2("application/x-ue-offer"sv); static constinit uint32_t HashCompressedBinary = HashStringDjb2("application/x-ue-comp"sv); +static constinit uint32_t HashJson = HashStringDjb2("json"sv); +static constinit uint32_t HashYaml = HashStringDjb2("yaml"sv); std::once_flag InitContentTypeLookup; @@ -81,14 +83,20 @@ struct HashedTypeEntry { uint32_t Hash; HttpContentType Type; -} TypeHashTable[] = {{HashBinary, HttpContentType::kBinary}, - {HashCompactBinary, HttpContentType::kCbObject}, - {HashCompactBinaryPackage, HttpContentType::kCbPackage}, - {HashCompactBinaryPackageOffer, HttpContentType::kCbPackageOffer}, - {HashJson, HttpContentType::kJSON}, - {HashYaml, HttpContentType::kYAML}, - {HashText, HttpContentType::kText}, - {HashCompressedBinary, HttpContentType::kCompressedBinary}}; +} TypeHashTable[] = { + // clang-format off + {HashBinary, HttpContentType::kBinary}, + {HashCompactBinary, HttpContentType::kCbObject}, + {HashCompactBinaryPackage, HttpContentType::kCbPackage}, + {HashCompactBinaryPackageOffer, HttpContentType::kCbPackageOffer}, + {HashJson, HttpContentType::kJSON}, + {HashApplicationJson, HttpContentType::kJSON}, + {HashYaml, HttpContentType::kYAML}, + {HashApplicationYaml, HttpContentType::kYAML}, + {HashText, HttpContentType::kText}, + {HashCompressedBinary, HttpContentType::kCompressedBinary} + // clang-format on +}; HttpContentType ParseContentTypeImpl(const std::string_view& ContentTypeString) @@ -120,6 +128,16 @@ ParseContentTypeInit(const std::string_view& ContentTypeString) std::sort(std::begin(TypeHashTable), std::end(TypeHashTable), [](const HashedTypeEntry& Lhs, const HashedTypeEntry& Rhs) { return Lhs.Hash < Rhs.Hash; }); + + // validate that there are no hash collisions + + uint32_t LastHash = 0; + + for (const auto& Item : TypeHashTable) + { + ZEN_ASSERT(LastHash != Item.Hash); + LastHash = Item.Hash; + } }); ParseContentType = ParseContentTypeImpl; -- cgit v1.2.3 From fa48ebf89e06edc9d3bdd26b119417df20902bdd Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Wed, 6 Oct 2021 13:59:18 +0200 Subject: Support for asynchronous HTTP response processing (#19) This change introduces WriteResponseAsync which can be used to move potentially slow request handler code (like upstream lookups) off the I/O service thread to ensure we are always able to serve as many HTTP requests as possible. The current implementation defaults to 16 async worker threads and there is currently no back-pressure. - Added RequestStats - Metrics for network requests. Aggregates tracking of duration, payload sizes into a single class for ease of use - Added some metrics on upstream communication Co-authored-by: Per Larsson --- zenhttp/httpserver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'zenhttp/httpserver.cpp') diff --git a/zenhttp/httpserver.cpp b/zenhttp/httpserver.cpp index 193426ed2..69974ca06 100644 --- a/zenhttp/httpserver.cpp +++ b/zenhttp/httpserver.cpp @@ -571,7 +571,7 @@ CreateHttpServer() #if 0 return new HttpUwsServer; #elif ZEN_WITH_HTTPSYS - return new HttpSysServer{std::thread::hardware_concurrency()}; + return new HttpSysServer(std::thread::hardware_concurrency(), /* background worker threads */ 16); #else return new HttpNullServer; #endif -- cgit v1.2.3