aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/servers/httptracer.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2024-03-14 12:53:17 +0000
committerGitHub Enterprise <[email protected]>2024-03-14 13:53:17 +0100
commit8ca82afb684abaebbe17c7748e522b6aef698e92 (patch)
tree698ab066b8158231a764412eda7d89b8d87182ea /src/zenhttp/servers/httptracer.cpp
parentadded notes on how to install git hooks (diff)
downloadzen-8ca82afb684abaebbe17c7748e522b6aef698e92.tar.xz
zen-8ca82afb684abaebbe17c7748e522b6aef698e92.zip
HTTP request logging (#6)
this change adds support for tracing http payloads when using the asio path. This was already supported when using the `--http=plugin` path and this change moves some code into a shared class for reuse.
Diffstat (limited to 'src/zenhttp/servers/httptracer.cpp')
-rw-r--r--src/zenhttp/servers/httptracer.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/zenhttp/servers/httptracer.cpp b/src/zenhttp/servers/httptracer.cpp
new file mode 100644
index 000000000..483307fb1
--- /dev/null
+++ b/src/zenhttp/servers/httptracer.cpp
@@ -0,0 +1,37 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#include "httptracer.h"
+
+#include <zencore/fmtutils.h>
+#include <zencore/logging.h>
+#include <zencore/session.h>
+
+namespace zen {
+
+void
+HttpServerTracer::Initialize(std::filesystem::path DataDir)
+{
+ m_DataDir = DataDir;
+ m_PayloadDir = DataDir / "debug" / GetSessionIdString();
+
+ ZEN_INFO("any debug payloads will be written to '{}'", m_PayloadDir);
+}
+
+void
+HttpServerTracer::WriteDebugPayload(std::string_view Filename, const std::span<const IoBuffer> Payload)
+{
+ uint64_t PayloadSize = 0;
+ std::vector<const IoBuffer*> Buffers;
+ for (auto& Io : Payload)
+ {
+ Buffers.push_back(&Io);
+ PayloadSize += Io.GetSize();
+ }
+
+ if (PayloadSize)
+ {
+ WriteFile(m_PayloadDir / Filename, Buffers.data(), Buffers.size());
+ }
+}
+
+} // namespace zen