aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-10-13 09:55:27 +0200
committerGitHub <[email protected]>2023-10-13 09:55:27 +0200
commit74d104d4eb3735e0881f0e1fccc2df8aa4d3f57d (patch)
treeacae59dac67b4d051403f35e580201c214ec4fda /src/zenhttp
parentfaster oplog iteration (#471) (diff)
downloadzen-74d104d4eb3735e0881f0e1fccc2df8aa4d3f57d.tar.xz
zen-74d104d4eb3735e0881f0e1fccc2df8aa4d3f57d.zip
restructured zenhttp (#472)
separating the http server implementations into a directory and moved diagsvcs into zenserver since it's somewhat hard-coded for it
Diffstat (limited to 'src/zenhttp')
-rw-r--r--src/zenhttp/diagsvcs.cpp135
-rw-r--r--src/zenhttp/httpserver.cpp7
-rw-r--r--src/zenhttp/include/zenhttp/diagsvcs.h119
-rw-r--r--src/zenhttp/servers/httpasio.cpp (renamed from src/zenhttp/httpasio.cpp)0
-rw-r--r--src/zenhttp/servers/httpasio.h (renamed from src/zenhttp/httpasio.h)0
-rw-r--r--src/zenhttp/servers/httpnull.cpp (renamed from src/zenhttp/httpnull.cpp)0
-rw-r--r--src/zenhttp/servers/httpnull.h (renamed from src/zenhttp/httpnull.h)0
-rw-r--r--src/zenhttp/servers/httpparser.cpp (renamed from src/zenhttp/httpparser.cpp)0
-rw-r--r--src/zenhttp/servers/httpparser.h (renamed from src/zenhttp/httpparser.h)0
-rw-r--r--src/zenhttp/servers/httpplugin.cpp (renamed from src/zenhttp/httpplugin.cpp)0
-rw-r--r--src/zenhttp/servers/httpsys.cpp (renamed from src/zenhttp/httpsys.cpp)0
-rw-r--r--src/zenhttp/servers/httpsys.h (renamed from src/zenhttp/httpsys.h)0
-rw-r--r--src/zenhttp/servers/iothreadpool.cpp (renamed from src/zenhttp/iothreadpool.cpp)0
-rw-r--r--src/zenhttp/servers/iothreadpool.h (renamed from src/zenhttp/iothreadpool.h)0
-rw-r--r--src/zenhttp/xmake.lua2
15 files changed, 4 insertions, 259 deletions
diff --git a/src/zenhttp/diagsvcs.cpp b/src/zenhttp/diagsvcs.cpp
deleted file mode 100644
index 9a547aa47..000000000
--- a/src/zenhttp/diagsvcs.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-// Copyright Epic Games, Inc. All Rights Reserved.
-
-#include "zenhttp/diagsvcs.h"
-
-#include <zencore/compactbinary.h>
-#include <zencore/compactbinarybuilder.h>
-#include <zencore/config.h>
-#include <zencore/filesystem.h>
-#include <zencore/logging.h>
-#include <zencore/string.h>
-#include <fstream>
-#include <sstream>
-
-#include <json11.hpp>
-
-namespace zen {
-
-using namespace std::literals;
-
-static bool
-ReadLogFile(const std::string& Path, StringBuilderBase& Out)
-{
- try
- {
- constexpr auto ReadSize = std::size_t{4096};
- auto FileStream = std::ifstream{Path};
-
- std::string Buf(ReadSize, '\0');
- while (FileStream.read(&Buf[0], ReadSize))
- {
- Out.Append(std::string_view(&Buf[0], FileStream.gcount()));
- }
- Out.Append(std::string_view(&Buf[0], FileStream.gcount()));
-
- return true;
- }
- catch (std::exception&)
- {
- Out.Reset();
- return false;
- }
-}
-
-HttpHealthService::HttpHealthService()
-{
- m_Router.RegisterRoute(
- "",
- [](HttpRouterRequest& RoutedReq) {
- HttpServerRequest& HttpReq = RoutedReq.ServerRequest();
- HttpReq.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, u8"OK!"sv);
- },
- HttpVerb::kGet);
-
- m_Router.RegisterRoute(
- "info",
- [this](HttpRouterRequest& RoutedReq) {
- HttpServerRequest& HttpReq = RoutedReq.ServerRequest();
-
- CbObjectWriter Writer;
-
- {
- RwLock::SharedLockScope _(m_InfoLock);
- Writer << "DataRoot"sv << m_HealthInfo.DataRoot.string();
- Writer << "AbsLogPath"sv << m_HealthInfo.AbsLogPath.string();
- Writer << "BuildVersion"sv << m_HealthInfo.BuildVersion;
- Writer << "HttpServerClass"sv << m_HealthInfo.HttpServerClass;
- }
-
- HttpReq.WriteResponse(HttpResponseCode::OK, Writer.Save());
- },
- HttpVerb::kGet);
-
- m_Router.RegisterRoute(
- "log",
- [this](HttpRouterRequest& RoutedReq) {
- HttpServerRequest& HttpReq = RoutedReq.ServerRequest();
-
- zen::Log().flush();
-
- std::filesystem::path Path = [&] {
- RwLock::SharedLockScope _(m_InfoLock);
- return m_HealthInfo.AbsLogPath.empty() ? m_HealthInfo.DataRoot / "logs/zenserver.log" : m_HealthInfo.AbsLogPath;
- }();
-
- ExtendableStringBuilder<4096> Sb;
- if (ReadLogFile(Path.string(), Sb) && Sb.Size() > 0)
- {
- HttpReq.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, Sb.ToView());
- }
- else
- {
- HttpReq.WriteResponse(HttpResponseCode::NotFound);
- }
- },
- HttpVerb::kGet);
-
- m_Router.RegisterRoute(
- "version",
- [this](HttpRouterRequest& RoutedReq) {
- HttpServerRequest& HttpReq = RoutedReq.ServerRequest();
- if (HttpReq.GetQueryParams().GetValue("detailed") == "true")
- {
- HttpReq.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, ZEN_CFG_VERSION_BUILD_STRING_FULL);
- }
- else
- {
- HttpReq.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, ZEN_CFG_VERSION);
- }
- },
- HttpVerb::kGet);
-}
-
-void
-HttpHealthService::SetHealthInfo(HealthServiceInfo&& Info)
-{
- RwLock::ExclusiveLockScope _(m_InfoLock);
- m_HealthInfo = std::move(Info);
-}
-
-const char*
-HttpHealthService::BaseUri() const
-{
- return "/health/";
-}
-
-void
-HttpHealthService::HandleRequest(HttpServerRequest& Request)
-{
- if (!m_Router.HandleRequest(Request))
- {
- Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, u8"OK!"sv);
- }
-}
-
-} // namespace zen
diff --git a/src/zenhttp/httpserver.cpp b/src/zenhttp/httpserver.cpp
index 7ea7cf91d..cd62ea157 100644
--- a/src/zenhttp/httpserver.cpp
+++ b/src/zenhttp/httpserver.cpp
@@ -2,10 +2,9 @@
#include <zenhttp/httpserver.h>
-#include "httpasio.h"
-#include "httpnull.h"
-#include "httpsys.h"
-
+#include "servers/httpasio.h"
+#include "servers/httpnull.h"
+#include "servers/httpsys.h"
#include "zenhttp/httpplugin.h"
#if ZEN_WITH_PLUGINS
diff --git a/src/zenhttp/include/zenhttp/diagsvcs.h b/src/zenhttp/include/zenhttp/diagsvcs.h
deleted file mode 100644
index 8cc869c83..000000000
--- a/src/zenhttp/include/zenhttp/diagsvcs.h
+++ /dev/null
@@ -1,119 +0,0 @@
-// Copyright Epic Games, Inc. All Rights Reserved.
-
-#pragma once
-
-#include <zencore/iobuffer.h>
-#include <zenhttp/httpserver.h>
-
-#include <filesystem>
-
-//////////////////////////////////////////////////////////////////////////
-
-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
-{
-public:
- HttpTestService() {}
- ~HttpTestService() = default;
-
- virtual const char* BaseUri() const override { return "/test/"; }
-
- virtual void HandleRequest(HttpServerRequest& Request) override
- {
- using namespace std::literals;
-
- auto Uri = Request.RelativeUri();
-
- if (Uri == "hello"sv)
- {
- Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, u8"hello world!"sv);
- }
- else if (Uri == "1K"sv)
- {
- Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kBinary, m_1k);
- }
- else if (Uri == "1M"sv)
- {
- Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kBinary, m_1m);
- }
- else if (Uri == "1M_1k"sv)
- {
- std::vector<IoBuffer> Buffers;
- Buffers.reserve(1024);
-
- for (int i = 0; i < 1024; ++i)
- {
- Buffers.push_back(m_1k);
- }
-
- Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kBinary, Buffers);
- }
- else if (Uri == "1G"sv)
- {
- std::vector<IoBuffer> Buffers;
- Buffers.reserve(1024);
-
- for (int i = 0; i < 1024; ++i)
- {
- Buffers.push_back(m_1m);
- }
-
- Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kBinary, Buffers);
- }
- else if (Uri == "1G_1k"sv)
- {
- std::vector<IoBuffer> Buffers;
- Buffers.reserve(1024 * 1024);
-
- for (int i = 0; i < 1024 * 1024; ++i)
- {
- Buffers.push_back(m_1k);
- }
-
- Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kBinary, Buffers);
- }
- }
-
-private:
- IoBuffer m_1m{1024 * 1024};
- IoBuffer m_1k{m_1m, 0u, 1024};
-};
-
-struct HealthServiceInfo
-{
- std::filesystem::path DataRoot;
- std::filesystem::path AbsLogPath;
- std::string HttpServerClass;
- std::string BuildVersion;
-};
-
-/** Health monitoring endpoint
-
- Thji
- */
-class HttpHealthService : public HttpService
-{
-public:
- HttpHealthService();
- ~HttpHealthService() = default;
-
- void SetHealthInfo(HealthServiceInfo&& Info);
-
- virtual const char* BaseUri() const override;
- virtual void HandleRequest(HttpServerRequest& Request) override final;
-
-private:
- HttpRequestRouter m_Router;
- RwLock m_InfoLock;
- HealthServiceInfo m_HealthInfo;
-};
-
-} // namespace zen
diff --git a/src/zenhttp/httpasio.cpp b/src/zenhttp/servers/httpasio.cpp
index 0c6b189f9..0c6b189f9 100644
--- a/src/zenhttp/httpasio.cpp
+++ b/src/zenhttp/servers/httpasio.cpp
diff --git a/src/zenhttp/httpasio.h b/src/zenhttp/servers/httpasio.h
index 2366f3437..2366f3437 100644
--- a/src/zenhttp/httpasio.h
+++ b/src/zenhttp/servers/httpasio.h
diff --git a/src/zenhttp/httpnull.cpp b/src/zenhttp/servers/httpnull.cpp
index 658f51831..658f51831 100644
--- a/src/zenhttp/httpnull.cpp
+++ b/src/zenhttp/servers/httpnull.cpp
diff --git a/src/zenhttp/httpnull.h b/src/zenhttp/servers/httpnull.h
index 965e729f7..965e729f7 100644
--- a/src/zenhttp/httpnull.h
+++ b/src/zenhttp/servers/httpnull.h
diff --git a/src/zenhttp/httpparser.cpp b/src/zenhttp/servers/httpparser.cpp
index 6b987151a..6b987151a 100644
--- a/src/zenhttp/httpparser.cpp
+++ b/src/zenhttp/servers/httpparser.cpp
diff --git a/src/zenhttp/httpparser.h b/src/zenhttp/servers/httpparser.h
index 219ac351d..219ac351d 100644
--- a/src/zenhttp/httpparser.h
+++ b/src/zenhttp/servers/httpparser.h
diff --git a/src/zenhttp/httpplugin.cpp b/src/zenhttp/servers/httpplugin.cpp
index 2e934473e..2e934473e 100644
--- a/src/zenhttp/httpplugin.cpp
+++ b/src/zenhttp/servers/httpplugin.cpp
diff --git a/src/zenhttp/httpsys.cpp b/src/zenhttp/servers/httpsys.cpp
index c1b4717cb..c1b4717cb 100644
--- a/src/zenhttp/httpsys.cpp
+++ b/src/zenhttp/servers/httpsys.cpp
diff --git a/src/zenhttp/httpsys.h b/src/zenhttp/servers/httpsys.h
index 6a6b16525..6a6b16525 100644
--- a/src/zenhttp/httpsys.h
+++ b/src/zenhttp/servers/httpsys.h
diff --git a/src/zenhttp/iothreadpool.cpp b/src/zenhttp/servers/iothreadpool.cpp
index da4b42e28..da4b42e28 100644
--- a/src/zenhttp/iothreadpool.cpp
+++ b/src/zenhttp/servers/iothreadpool.cpp
diff --git a/src/zenhttp/iothreadpool.h b/src/zenhttp/servers/iothreadpool.h
index e75e95e58..e75e95e58 100644
--- a/src/zenhttp/iothreadpool.h
+++ b/src/zenhttp/servers/iothreadpool.h
diff --git a/src/zenhttp/xmake.lua b/src/zenhttp/xmake.lua
index 588fd8b87..e90fdfd1c 100644
--- a/src/zenhttp/xmake.lua
+++ b/src/zenhttp/xmake.lua
@@ -5,7 +5,7 @@ target('zenhttp')
set_group("libs")
add_headerfiles("**.h")
add_files("**.cpp")
- add_files("httpsys.cpp", {unity_ignored=true})
+ add_files("servers/httpsys.cpp", {unity_ignored=true})
add_includedirs("include", {public=true})
add_deps("zencore", "transport-sdk")
add_packages(