aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/servers/httpplugin.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/httpplugin.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/httpplugin.cpp')
-rw-r--r--src/zenhttp/servers/httpplugin.cpp37
1 files changed, 9 insertions, 28 deletions
diff --git a/src/zenhttp/servers/httpplugin.cpp b/src/zenhttp/servers/httpplugin.cpp
index 3eed9db8f..4a2615133 100644
--- a/src/zenhttp/servers/httpplugin.cpp
+++ b/src/zenhttp/servers/httpplugin.cpp
@@ -2,6 +2,8 @@
#include <zenhttp/httpplugin.h>
+#include "httptracer.h"
+
#if ZEN_WITH_PLUGINS
# include "httpparser.h"
@@ -103,8 +105,6 @@ struct HttpPluginServerImpl : public HttpPluginServer, TransportServer
HttpService* RouteRequest(std::string_view Url);
- void WriteDebugPayload(std::string_view Filename, const std::span<const IoBuffer> Payload);
-
struct ServiceEntry
{
std::string ServiceUrlPath;
@@ -119,8 +119,8 @@ struct HttpPluginServerImpl : public HttpPluginServer, TransportServer
bool m_IsRequestLoggingEnabled = false;
LoggerRef m_RequestLog;
std::atomic_uint32_t m_ConnectionIdCounter{0};
- std::filesystem::path m_DataDir; // Application data directory
- std::filesystem::path m_PayloadDir; // Request debugging payload directory
+
+ HttpServerTracer m_RequestTracer;
// TransportServer
@@ -376,8 +376,8 @@ HttpPluginConnectionHandler::HandleRequest()
ToString(Request.RequestContentType()),
ToString(Request.AcceptContentType()));
- m_Server->WriteDebugPayload(fmt::format("request_{}_{}.bin", m_ConnectionId, RequestNumber),
- std::vector<IoBuffer>{Request.ReadPayload()});
+ m_Server->m_RequestTracer.WriteDebugPayload(fmt::format("request_{}_{}.bin", m_ConnectionId, RequestNumber),
+ std::vector<IoBuffer>{Request.ReadPayload()});
}
if (!HandlePackageOffers(*Service, Request, m_PackageHandler))
@@ -442,7 +442,8 @@ HttpPluginConnectionHandler::HandleRequest()
if (m_Server->m_RequestLog.ShouldLog(logging::level::Trace))
{
- m_Server->WriteDebugPayload(fmt::format("response_{}_{}.bin", m_ConnectionId, RequestNumber), ResponseBuffers);
+ m_Server->m_RequestTracer.WriteDebugPayload(fmt::format("response_{}_{}.bin", m_ConnectionId, RequestNumber),
+ ResponseBuffers);
}
for (const IoBuffer& Buffer : ResponseBuffers)
@@ -678,10 +679,7 @@ HttpPluginServerImpl::CreateConnectionHandler(TransportConnection* Connection)
int
HttpPluginServerImpl::Initialize(int BasePort, std::filesystem::path DataDir)
{
- m_DataDir = DataDir;
- m_PayloadDir = DataDir / "debug" / GetSessionIdString();
-
- ZEN_INFO("any debug payloads will be written to '{}'", m_PayloadDir);
+ m_RequestTracer.Initialize(DataDir);
try
{
@@ -848,23 +846,6 @@ HttpPluginServerImpl::RouteRequest(std::string_view Url)
return CandidateService;
}
-void
-HttpPluginServerImpl::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());
- }
-}
-
//////////////////////////////////////////////////////////////////////////
struct HttpPluginServerImpl;