aboutsummaryrefslogtreecommitdiff
path: root/zenhttp
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-09-21 11:06:13 +0200
committerMartin Ridgers <[email protected]>2021-09-21 11:06:13 +0200
commit68c951e0f440ffd483795dced737e88152c1a581 (patch)
tree5c0910ca2a85b45fb05dba3ce457b7d156213894 /zenhttp
parentMerge main into linux-mac (diff)
parentTrigger storage scrubbing pass at startup (diff)
downloadzen-68c951e0f440ffd483795dced737e88152c1a581.tar.xz
zen-68c951e0f440ffd483795dced737e88152c1a581.zip
Merged main into linux-mac
Diffstat (limited to 'zenhttp')
-rw-r--r--zenhttp/httpclient.cpp7
-rw-r--r--zenhttp/httpnull.cpp4
-rw-r--r--zenhttp/httpnull.h2
-rw-r--r--zenhttp/httpserver.cpp7
-rw-r--r--zenhttp/httpshared.cpp9
-rw-r--r--zenhttp/httpsys.cpp36
-rw-r--r--zenhttp/httpuws.cpp4
-rw-r--r--zenhttp/httpuws.h2
-rw-r--r--zenhttp/include/zenhttp/httpserver.h4
9 files changed, 42 insertions, 33 deletions
diff --git a/zenhttp/httpclient.cpp b/zenhttp/httpclient.cpp
index fb1df30b2..20550b0c9 100644
--- a/zenhttp/httpclient.cpp
+++ b/zenhttp/httpclient.cpp
@@ -10,10 +10,9 @@
#include <zencore/session.h>
#include <zencore/sharedbuffer.h>
#include <zencore/stream.h>
+#include <zencore/testing.h>
#include <zenhttp/httpshared.h>
-#include <doctest/doctest.h>
-
static std::atomic<uint32_t> HttpClientRequestIdCounter{0};
namespace zen {
@@ -159,6 +158,8 @@ HttpClient::Delete(std::string_view Url)
//////////////////////////////////////////////////////////////////////////
+#if ZEN_WITH_TESTS
+
TEST_CASE("httpclient")
{
using namespace std::literals;
@@ -171,4 +172,6 @@ httpclient_forcelink()
{
}
+#endif
+
} // namespace zen
diff --git a/zenhttp/httpnull.cpp b/zenhttp/httpnull.cpp
index 57cba13d3..e49051ac5 100644
--- a/zenhttp/httpnull.cpp
+++ b/zenhttp/httpnull.cpp
@@ -28,8 +28,10 @@ HttpNullServer::Initialize(int BasePort)
}
void
-HttpNullServer::Run(bool TestMode)
+HttpNullServer::Run(bool IsInteractiveSession)
{
+ const bool TestMode = !IsInteractiveSession;
+
if (TestMode == false)
{
zen::logging::ConsoleLog().info("Zen Server running (null HTTP). Press ESC or Q to quit");
diff --git a/zenhttp/httpnull.h b/zenhttp/httpnull.h
index b15b1b123..867bbe4d2 100644
--- a/zenhttp/httpnull.h
+++ b/zenhttp/httpnull.h
@@ -19,7 +19,7 @@ public:
virtual void RegisterService(HttpService& Service) override;
virtual void Initialize(int BasePort) override;
- virtual void Run(bool TestMode) override;
+ virtual void Run(bool IsInteractiveSession) override;
virtual void RequestExit() override;
private:
diff --git a/zenhttp/httpserver.cpp b/zenhttp/httpserver.cpp
index 62ee66a08..599c99a18 100644
--- a/zenhttp/httpserver.cpp
+++ b/zenhttp/httpserver.cpp
@@ -13,6 +13,7 @@
#include <zencore/refcount.h>
#include <zencore/stream.h>
#include <zencore/string.h>
+#include <zencore/testing.h>
#include <zencore/thread.h>
#include <zenhttp/httpshared.h>
@@ -23,8 +24,6 @@
#include <span>
#include <string_view>
-#include <doctest/doctest.h>
-
namespace zen {
using namespace std::literals;
@@ -525,6 +524,8 @@ CreateHttpServer()
//////////////////////////////////////////////////////////////////////////
+#if ZEN_WITH_TESTS
+
TEST_CASE("http.common")
{
using namespace std::literals;
@@ -566,4 +567,6 @@ http_forcelink()
{
}
+#endif
+
} // namespace zen
diff --git a/zenhttp/httpshared.cpp b/zenhttp/httpshared.cpp
index 2dbf95959..b0c5493db 100644
--- a/zenhttp/httpshared.cpp
+++ b/zenhttp/httpshared.cpp
@@ -123,23 +123,22 @@ ParsePackageMessage(IoBuffer Payload, std::function<IoBuffer(const IoHash&, uint
MemoryInStream InStream(Payload);
BinaryReader Reader(InStream);
- CbPackage Package;
-
CbPackageHeader Hdr;
Reader.Read(&Hdr, sizeof Hdr);
if (Hdr.HeaderMagic != kCbPkgMagic)
{
- // report error
- return {};
+ throw std::runtime_error("invalid CbPackage header magic");
}
- uint32_t ChunkCount = Hdr.AttachmentCount + 1;
+ const uint32_t ChunkCount = Hdr.AttachmentCount + 1;
std::unique_ptr<CbAttachmentEntry[]> AttachmentEntries{new CbAttachmentEntry[ChunkCount]};
Reader.Read(AttachmentEntries.get(), sizeof(CbAttachmentEntry) * ChunkCount);
+ CbPackage Package;
+
for (uint32_t i = 0; i < ChunkCount; ++i)
{
const CbAttachmentEntry& Entry = AttachmentEntries[i];
diff --git a/zenhttp/httpsys.cpp b/zenhttp/httpsys.cpp
index d70c88271..087d4c807 100644
--- a/zenhttp/httpsys.cpp
+++ b/zenhttp/httpsys.cpp
@@ -415,7 +415,7 @@ HttpMessageResponseRequest::HandleCompletion(ULONG IoResult, ULONG_PTR NumberOfB
{
ZEN_UNUSED(NumberOfBytesTransferred);
- if (IoResult)
+ if (IoResult != NO_ERROR)
{
ZEN_WARN("response aborted due to error: '{}'", GetErrorAsString(IoResult));
@@ -707,29 +707,30 @@ HttpSysServer::StartServer()
}
void
-HttpSysServer::Run(bool TestMode)
+HttpSysServer::Run(bool IsInteractive)
{
- if (TestMode == false)
+ if (IsInteractive)
{
zen::logging::ConsoleLog().info("Zen Server running. Press ESC or Q to quit");
}
do
{
- int WaitTimeout = -1;
+ // int WaitTimeout = -1;
+ int WaitTimeout = 100;
- if (!TestMode)
+ if (IsInteractive)
{
WaitTimeout = 1000;
- }
-
- if (!TestMode && _kbhit() != 0)
- {
- char c = (char)_getch();
- if (c == 27 || c == 'Q' || c == 'q')
+ if (_kbhit() != 0)
{
- RequestApplicationExit(0);
+ char c = (char)_getch();
+
+ if (c == 27 || c == 'Q' || c == 'q')
+ {
+ RequestApplicationExit(0);
+ }
}
}
@@ -897,9 +898,7 @@ HttpSysTransaction::HandleCompletion(ULONG IoResult, ULONG_PTR NumberOfBytesTran
if (HttpSysRequestHandler* CurrentHandler = m_CompletionHandler)
{
- const bool IsInitialRequest = (CurrentHandler == &m_InitialHttpHandler) && m_InitialHttpHandler.IsInitialRequest();
-
- if (IsInitialRequest)
+ if ((CurrentHandler == &m_InitialHttpHandler) && m_InitialHttpHandler.IsInitialRequest())
{
// Ensure we have a sufficient number of pending requests outstanding
m_HttpServer.OnHandlingRequest();
@@ -932,7 +931,7 @@ HttpSysTransaction::HandleCompletion(ULONG IoResult, ULONG_PTR NumberOfBytesTran
}
else
{
- if (IsInitialRequest == false)
+ if (CurrentHandler != &m_InitialHttpHandler)
{
delete CurrentHandler;
}
@@ -1253,11 +1252,12 @@ InitialRequestHandler::HandleCompletion(ULONG IoResult, ULONG_PTR NumberOfBytesT
switch (IoResult)
{
+ default:
case ERROR_OPERATION_ABORTED:
return nullptr;
- case ERROR_MORE_DATA:
- // Insufficient buffer space
+ case ERROR_MORE_DATA: // Insufficient buffer space
+ case NO_ERROR:
break;
}
diff --git a/zenhttp/httpuws.cpp b/zenhttp/httpuws.cpp
index 992809b17..e062e7747 100644
--- a/zenhttp/httpuws.cpp
+++ b/zenhttp/httpuws.cpp
@@ -37,8 +37,10 @@ HttpUwsServer::Initialize(int BasePort)
}
void
-HttpUwsServer::Run(bool TestMode)
+HttpUwsServer::Run(bool IsInteractive)
{
+ const bool TestMode = !IsInteractive;
+
if (TestMode == false)
{
zen::logging::ConsoleLog().info("Zen Server running (null HTTP). Press ESC or Q to quit");
diff --git a/zenhttp/httpuws.h b/zenhttp/httpuws.h
index ec55ae2fd..5e300202f 100644
--- a/zenhttp/httpuws.h
+++ b/zenhttp/httpuws.h
@@ -16,7 +16,7 @@ public:
virtual void RegisterService(HttpService& Service) override;
virtual void Initialize(int BasePort) override;
- virtual void Run(bool TestMode) override;
+ virtual void Run(bool IsInteractiveSession) override;
virtual void RequestExit() override;
private:
diff --git a/zenhttp/include/zenhttp/httpserver.h b/zenhttp/include/zenhttp/httpserver.h
index f656c69a8..6a7dc8a70 100644
--- a/zenhttp/include/zenhttp/httpserver.h
+++ b/zenhttp/include/zenhttp/httpserver.h
@@ -39,7 +39,7 @@ public:
{
std::vector<std::pair<std::string_view, std::string_view>> KvPairs;
- std::string_view GetValue(std::string_view ParamName)
+ std::string_view GetValue(std::string_view ParamName) const
{
for (const auto& Kv : KvPairs)
{
@@ -167,7 +167,7 @@ class HttpServer : public RefCounted
public:
virtual void RegisterService(HttpService& Service) = 0;
virtual void Initialize(int BasePort) = 0;
- virtual void Run(bool TestMode) = 0;
+ virtual void Run(bool IsInteractiveSession) = 0;
virtual void RequestExit() = 0;
};