]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
An HttpException creates a new response body. 11854/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 16 Aug 2022 08:00:52 +0000 (10:00 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 16 Aug 2022 08:00:52 +0000 (10:00 +0200)
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

index 78039890106cbf226b75b406215ca2504f5b1fe9..9565f4ba04b0e6ace1320af7fa94335c1e51651c 100644 (file)
@@ -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<<Logger::Debug<<req.logprefix<<"Incomplete request" << endl,
            d_slog->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<<Logger::Debug<<req.logprefix<<"Handling request \"" << req.url.path << "\"" << endl,
          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<<Logger::Debug<<req.logprefix<<"Error result for \"" << req.url.path << "\": " << resp.status << endl,
          d_slog->error(Logr::Debug, resp.status, "Error result", "urlpath", Logging::Loggable(req.url.path)));