aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2026-02-17 13:56:33 +0100
committerGitHub Enterprise <[email protected]>2026-02-17 13:56:33 +0100
commit2159b2ce105935ce4d52a726094f9bbb91537d0c (patch)
tree6f8b21486d6dfa4e7d188bd83a56cbfdf4436b22 /src/zenhttp
parentadded ResetConsoleLog (#758) (diff)
downloadzen-2159b2ce105935ce4d52a726094f9bbb91537d0c.tar.xz
zen-2159b2ce105935ce4d52a726094f9bbb91537d0c.zip
misc fixes brought over from sb/proto (#759)
* `RwLock::WithSharedLock` and `RwLock::WithExclusiveLock` can now return a value (which is returned by the passed function) * Comma-separated logger specification now correctly deals with commas * `GetSystemMetrics` properly accounts for cores * cpr response formatter passes arguments in the right order * `HttpServerRequest::SetLogRequest` can be used to selectively log HTTP requests
Diffstat (limited to 'src/zenhttp')
-rw-r--r--src/zenhttp/include/zenhttp/cprutils.h4
-rw-r--r--src/zenhttp/include/zenhttp/httpserver.h17
-rw-r--r--src/zenhttp/servers/httpasio.cpp7
-rw-r--r--src/zenhttp/servers/httpsys.cpp30
4 files changed, 38 insertions, 20 deletions
diff --git a/src/zenhttp/include/zenhttp/cprutils.h b/src/zenhttp/include/zenhttp/cprutils.h
index a988346e0..c252a5d99 100644
--- a/src/zenhttp/include/zenhttp/cprutils.h
+++ b/src/zenhttp/include/zenhttp/cprutils.h
@@ -66,10 +66,10 @@ struct fmt::formatter<cpr::Response>
Response.url.str(),
Response.status_code,
zen::ToString(zen::HttpResponseCode(Response.status_code)),
+ Response.reason,
Response.uploaded_bytes,
Response.downloaded_bytes,
NiceResponseTime.c_str(),
- Response.reason,
Json);
}
else
@@ -82,10 +82,10 @@ struct fmt::formatter<cpr::Response>
Response.url.str(),
Response.status_code,
zen::ToString(zen::HttpResponseCode(Response.status_code)),
+ Response.reason,
Response.uploaded_bytes,
Response.downloaded_bytes,
NiceResponseTime.c_str(),
- Response.reason,
Body.GetText());
}
}
diff --git a/src/zenhttp/include/zenhttp/httpserver.h b/src/zenhttp/include/zenhttp/httpserver.h
index 60f6bc9f2..cbac06cb6 100644
--- a/src/zenhttp/include/zenhttp/httpserver.h
+++ b/src/zenhttp/include/zenhttp/httpserver.h
@@ -39,7 +39,7 @@ public:
// Synchronous operations
[[nodiscard]] inline std::string_view RelativeUri() const { return m_Uri; } // Returns URI without service prefix
- [[nodiscard]] std::string_view RelativeUriWithExtension() const { return m_UriWithExtension; }
+ [[nodiscard]] inline std::string_view RelativeUriWithExtension() const { return m_UriWithExtension; }
[[nodiscard]] inline std::string_view QueryString() const { return m_QueryString; }
[[nodiscard]] inline HttpService& Service() const { return m_Service; }
@@ -81,6 +81,18 @@ public:
inline bool IsHandled() const { return !!(m_Flags & kIsHandled); }
inline bool SuppressBody() const { return !!(m_Flags & kSuppressBody); }
inline void SetSuppressResponseBody() { m_Flags |= kSuppressBody; }
+ inline void SetLogRequest(bool ShouldLog)
+ {
+ if (ShouldLog)
+ {
+ m_Flags |= kLogRequest;
+ }
+ else
+ {
+ m_Flags &= ~kLogRequest;
+ }
+ }
+ inline bool ShouldLogRequest() const { return !!(m_Flags & kLogRequest); }
/** Read POST/PUT payload for request body, which is always available without delay
*/
@@ -119,6 +131,7 @@ protected:
kSuppressBody = 1 << 1,
kHaveRequestId = 1 << 2,
kHaveSessionId = 1 << 3,
+ kLogRequest = 1 << 4,
};
mutable uint32_t m_Flags = 0;
@@ -254,7 +267,7 @@ public:
inline HttpServerRequest& ServerRequest() { return m_HttpRequest; }
private:
- HttpRouterRequest(HttpServerRequest& Request) : m_HttpRequest(Request) {}
+ explicit HttpRouterRequest(HttpServerRequest& Request) : m_HttpRequest(Request) {}
~HttpRouterRequest() = default;
HttpRouterRequest(const HttpRouterRequest&) = delete;
diff --git a/src/zenhttp/servers/httpasio.cpp b/src/zenhttp/servers/httpasio.cpp
index 230aac6a8..1f42b05d2 100644
--- a/src/zenhttp/servers/httpasio.cpp
+++ b/src/zenhttp/servers/httpasio.cpp
@@ -147,7 +147,7 @@ inline LoggerRef
InitLogger()
{
LoggerRef Logger = logging::Get("asio");
- // Logger.set_level(spdlog::level::trace);
+ // Logger.SetLogLevel(logging::level::Trace);
return Logger;
}
@@ -1264,6 +1264,11 @@ HttpServerConnection::HandleRequest()
if (std::unique_ptr<HttpResponse> Response = std::move(Request.m_Response))
{
+ if (Request.ShouldLogRequest())
+ {
+ ZEN_INFO("{} {} {} -> {}", ToString(RequestVerb), Uri, Response->ResponseCode(), NiceBytes(Response->ContentLength()));
+ }
+
// Transmit the response
if (m_RequestData.RequestVerb() == HttpVerb::kHead)
diff --git a/src/zenhttp/servers/httpsys.cpp b/src/zenhttp/servers/httpsys.cpp
index 4df4cd079..5fed94f1c 100644
--- a/src/zenhttp/servers/httpsys.cpp
+++ b/src/zenhttp/servers/httpsys.cpp
@@ -702,21 +702,22 @@ HttpMessageResponseRequest::IssueRequest(std::error_code& ErrorCode)
HTTP_CACHE_POLICY CachePolicy;
- CachePolicy.Policy = HttpCachePolicyNocache; // HttpCachePolicyUserInvalidates;
+ CachePolicy.Policy = HttpCachePolicyNocache;
CachePolicy.SecondsToLive = 0;
// Initial response API call
- SendResult = HttpSendHttpResponse(Tx.RequestQueueHandle(),
- HttpReq->RequestId,
- SendFlags,
- &HttpResponse,
- &CachePolicy,
- NULL,
- NULL,
- 0,
- Tx.Overlapped(),
- NULL);
+ SendResult = HttpSendHttpResponse(Tx.RequestQueueHandle(), // RequestQueueHandle
+ HttpReq->RequestId, // RequestId
+ SendFlags, // Flags
+ &HttpResponse, // HttpResponse
+ &CachePolicy, // CachePolicy
+ NULL, // BytesSent
+ NULL, // Reserved1
+ 0, // Reserved2
+ Tx.Overlapped(), // Overlapped
+ NULL // LogData
+ );
m_IsInitialResponse = false;
}
@@ -724,9 +725,9 @@ HttpMessageResponseRequest::IssueRequest(std::error_code& ErrorCode)
{
// Subsequent response API calls
- SendResult = HttpSendResponseEntityBody(Tx.RequestQueueHandle(),
- HttpReq->RequestId,
- SendFlags,
+ SendResult = HttpSendResponseEntityBody(Tx.RequestQueueHandle(), // RequestQueueHandle
+ HttpReq->RequestId, // RequestId
+ SendFlags, // Flags
(USHORT)ThisRequestChunkCount, // EntityChunkCount
&m_HttpDataChunks[ThisRequestChunkOffset], // EntityChunks
NULL, // BytesSent
@@ -1351,7 +1352,6 @@ HttpSysServer::OnRun(bool IsInteractive)
bool ShutdownRequested = false;
do
{
- // int WaitTimeout = -1;
int WaitTimeout = 100;
if (IsInteractive)