Log the response length for static files in the docker server

The access log took $body_bytes_sent from res.body, which stays empty
for a static file because it is sent by a content provider. Every file
was logged as 0 bytes. Use the Content-Length of the response instead,
and 0 for HEAD.
This commit is contained in:
yhirose
2026-10-08 00:39:01 -04:00
parent 8aa547e4a1
commit f6aee694e2

View File

@@ -76,7 +76,9 @@ void nginx_access_logger(const Request &req, const Response &res) {
// the percent-decoded req.path.
auto request = std::format("{} {} {}", req.method, req.target, req.version);
auto status = res.status;
auto body_bytes_sent = res.body.size();
// A static file is sent by a content provider, which leaves res.body empty.
auto body_bytes_sent =
req.method == "HEAD" ? 0 : res.get_header_value_u64("Content-Length");
auto http_referer = req.get_header_value("Referer");
if (http_referer.empty()) http_referer = "-";
auto http_user_agent = req.get_header_value("User-Agent");