aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/servers/httpasio.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/httpasio.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/httpasio.cpp')
-rw-r--r--src/zenhttp/servers/httpasio.cpp39
1 files changed, 36 insertions, 3 deletions
diff --git a/src/zenhttp/servers/httpasio.cpp b/src/zenhttp/servers/httpasio.cpp
index 7ef0437c3..de71eb0a7 100644
--- a/src/zenhttp/servers/httpasio.cpp
+++ b/src/zenhttp/servers/httpasio.cpp
@@ -1,6 +1,7 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#include "httpasio.h"
+#include "httptracer.h"
#include <zencore/except.h>
#include <zencore/logging.h>
@@ -62,6 +63,7 @@ public:
HttpAsioServerImpl();
~HttpAsioServerImpl();
+ void Initialize(std::filesystem::path DataDir);
int Start(uint16_t Port, bool ForceLooopback, int ThreadCount);
void Stop();
void RegisterService(const char* UrlPath, HttpService& Service);
@@ -72,6 +74,9 @@ public:
std::unique_ptr<asio_http::HttpAcceptor> m_Acceptor;
std::vector<std::thread> m_ThreadPool;
+ LoggerRef m_RequestLog;
+ HttpServerTracer m_RequestTracer;
+
struct ServiceEntry
{
std::string ServiceUrlPath;
@@ -441,9 +446,29 @@ HttpServerConnection::HandleRequest()
{
ZEN_TRACE_CPU("asio::HandleRequest");
+ const uint32_t RequestNumber = m_RequestCounter.load(std::memory_order_relaxed);
+
HttpAsioServerRequest Request(m_RequestData, *Service, m_RequestData.Body());
- ZEN_TRACE_VERBOSE("handle request, connection: {}, request: {}'", m_ConnectionId, m_RequestCounter.load(std::memory_order_relaxed));
+ ZEN_TRACE_VERBOSE("handle request, connection: {}, request: {}'", m_ConnectionId, RequestNumber);
+
+ const HttpVerb RequestVerb = Request.RequestVerb();
+ const std::string_view Uri = Request.RelativeUri();
+
+ if (m_Server.m_RequestLog.ShouldLog(logging::level::Trace))
+ {
+ ZEN_LOG_TRACE(m_Server.m_RequestLog,
+ "connection #{} Handling Request: {} {} ({} bytes ({}), accept: {})",
+ m_ConnectionId,
+ ToString(RequestVerb),
+ Uri,
+ Request.ContentLength(),
+ ToString(Request.RequestContentType()),
+ ToString(Request.AcceptContentType()));
+
+ m_Server.m_RequestTracer.WriteDebugPayload(fmt::format("request_{}_{}.bin", m_ConnectionId, RequestNumber),
+ std::vector<IoBuffer>{Request.ReadPayload()});
+ }
if (!HandlePackageOffers(*Service, Request, m_PackageHandler))
{
@@ -891,7 +916,7 @@ HttpAsioServerRequest::TryGetRanges(HttpRanges& Ranges)
//////////////////////////////////////////////////////////////////////////
-HttpAsioServerImpl::HttpAsioServerImpl()
+HttpAsioServerImpl::HttpAsioServerImpl() : m_RequestLog(logging::Get("http_requests"))
{
}
@@ -899,6 +924,12 @@ HttpAsioServerImpl::~HttpAsioServerImpl()
{
}
+void
+HttpAsioServerImpl::Initialize(std::filesystem::path DataDir)
+{
+ m_RequestTracer.Initialize(DataDir);
+}
+
int
HttpAsioServerImpl::Start(uint16_t Port, bool ForceLooopback, int ThreadCount)
{
@@ -1060,8 +1091,10 @@ HttpAsioServer::RegisterService(HttpService& Service)
int
HttpAsioServer::Initialize(int BasePort, std::filesystem::path DataDir)
{
- ZEN_UNUSED(DataDir);
+ m_Impl->Initialize(DataDir);
+
m_BasePort = m_Impl->Start(gsl::narrow<uint16_t>(BasePort), m_ForceLoopback, m_ThreadCount);
+
return m_BasePort;
}