aboutsummaryrefslogtreecommitdiff
path: root/zencore/httpserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'zencore/httpserver.cpp')
-rw-r--r--zencore/httpserver.cpp97
1 files changed, 13 insertions, 84 deletions
diff --git a/zencore/httpserver.cpp b/zencore/httpserver.cpp
index b40b74208..4b6bd1c0a 100644
--- a/zencore/httpserver.cpp
+++ b/zencore/httpserver.cpp
@@ -4,8 +4,6 @@
#include "httpsys.h"
-#include <conio.h>
-#include <new.h>
#include <zencore/compactbinary.h>
#include <zencore/compactbinarypackage.h>
#include <zencore/iobuffer.h>
@@ -14,22 +12,17 @@
#include <zencore/stream.h>
#include <zencore/string.h>
#include <zencore/thread.h>
+
+#include <conio.h>
+#include <new.h>
#include <charconv>
#include <span>
#include <string_view>
-#include <spdlog/spdlog.h>
-
#include <doctest/doctest.h>
-//////////////////////////////////////////////////////////////////////////
-
namespace zen {
-using namespace std::literals;
-
-//////////////////////////////////////////////////////////////////////////
-
HttpServerRequest::HttpServerRequest()
{
}
@@ -242,80 +235,6 @@ HttpServerRequest::ReadPayloadPackage()
//////////////////////////////////////////////////////////////////////////
-struct HttpServer::Impl : public RefCounted
-{
- WinIoThreadPool m_ThreadPool;
- HttpSysServer m_HttpServer;
-
- Impl(int ThreadCount) : m_ThreadPool(ThreadCount), m_HttpServer(m_ThreadPool) {}
-
- void Initialize(int BasePort)
- {
- using namespace std::literals;
-
- WideStringBuilder<64> BaseUri;
- BaseUri << u8"http://*:"sv << int64_t(BasePort) << u8"/"sv;
-
- m_HttpServer.Initialize(BaseUri.c_str());
- m_HttpServer.StartServer();
- }
-
- void Run(bool TestMode) { m_HttpServer.Run(TestMode); }
-
- void RequestExit() { m_HttpServer.RequestExit(); }
-
- void Cleanup() { m_HttpServer.StopServer(); }
-
- void AddEndpoint(const char* Endpoint, HttpService& Service) { m_HttpServer.AddEndpoint(Endpoint, Service); }
-
- void AddEndpoint([[maybe_unused]] const char* endpoint, [[maybe_unused]] std::function<void(HttpServerRequest&)> handler)
- {
- ZEN_NOT_IMPLEMENTED();
- }
-};
-
-HttpServer::HttpServer()
-{
- m_Impl = new Impl(32);
-}
-
-HttpServer::~HttpServer()
-{
- m_Impl->Cleanup();
-}
-
-void
-HttpServer::AddEndpoint(HttpService& Service)
-{
- m_Impl->AddEndpoint(Service.BaseUri(), Service);
-}
-
-void
-HttpServer::AddEndpoint(const char* endpoint, std::function<void(HttpServerRequest&)> handler)
-{
- m_Impl->AddEndpoint(endpoint, handler);
-}
-
-void
-HttpServer::Initialize(int BasePort)
-{
- m_Impl->Initialize(BasePort);
-}
-
-void
-HttpServer::Run(bool TestMode)
-{
- m_Impl->Run(TestMode);
-}
-
-void
-HttpServer::RequestExit()
-{
- m_Impl->RequestExit();
-}
-
-//////////////////////////////////////////////////////////////////////////
-
HttpServerException::HttpServerException(const char* Message, uint32_t Error) : m_ErrorCode(Error)
{
using namespace fmt::literals;
@@ -429,6 +348,16 @@ HttpRequestRouter::HandleRequest(zen::HttpServerRequest& Request)
return false; // No route matched
}
+//////////////////////////////////////////////////////////////////////////
+
+Ref<HttpServer>
+CreateHttpServer()
+{
+ return new HttpSysServer{32};
+}
+
+//////////////////////////////////////////////////////////////////////////
+
TEST_CASE("http")
{
using namespace std::literals;