From 3e285251939365980477cdd805684c34fd962276 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Tue, 16 Aug 2022 10:00:52 +0200 Subject: [PATCH] An HttpException creates a new response body. Initialize the s_dlog field of that new response. I would prefer to do that in the exception's ct, but we do not have the uniqueid there. --- pdns/webserver.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pdns/webserver.cc b/pdns/webserver.cc index 7803989010..9565f4ba04 100644 --- a/pdns/webserver.cc +++ b/pdns/webserver.cc @@ -262,15 +262,16 @@ void WebServer::handleRequest(HttpRequest& req, HttpResponse& resp) const // set default headers resp.headers["Content-Type"] = "text/html; charset=utf-8"; +#ifdef RECURSOR + auto log = req.d_slog->withValues("urlpath", Logging::Loggable(req.url.path)); +#endif + try { if (!req.complete) { SLOG(g_log<info(Logr::Debug, "Incomplete request")); throw HttpBadRequestException(); } -#ifdef RECURSOR - auto log = req.d_slog->withValues("urlpath", Logging::Loggable(req.url.path)); -#endif SLOG(g_log<info(Logr::Debug, "Handling request")); @@ -323,6 +324,12 @@ void WebServer::handleRequest(HttpRequest& req, HttpResponse& resp) const } catch(HttpException &e) { resp = e.response(); +#ifdef RECURSOR + // An HttpException does not initialize d_slog + if (!resp.d_slog) { + resp.setSLog(log); + } +#endif // TODO rm this logline? SLOG(g_log<error(Logr::Debug, resp.status, "Error result", "urlpath", Logging::Loggable(req.url.path))); -- 2.47.2