From: Pieter Lexis Date: Fri, 25 Jan 2019 17:49:55 +0000 (+0100) Subject: Add better logging to the AsyncWebserver X-Git-Tag: dnsdist-1.4.0-alpha1~39^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b030ea34891a3af2ad77827938cccd68a9244bdf;p=thirdparty%2Fpdns.git Add better logging to the AsyncWebserver --- diff --git a/pdns/ws-recursor.cc b/pdns/ws-recursor.cc index 5e1481512c..8ae6a1f3f2 100644 --- a/pdns/ws-recursor.cc +++ b/pdns/ws-recursor.cc @@ -41,6 +41,7 @@ #include "ext/incbin/incbin.h" #include "rec-lua-conf.hh" #include "rpzloader.hh" +#include "uuid-utils.hh" extern thread_local FDMultiplexer* t_fdm; @@ -621,50 +622,120 @@ void AsyncServer::newConnection() } // This is an entry point from FDM, so it needs to catch everything. -void AsyncWebServer::serveConnection(std::shared_ptr client) const -try { - HttpRequest req; - YaHTTP::AsyncRequestLoader yarl; - yarl.initialize(&req); - client->setNonBlocking(); - - string data; +void AsyncWebServer::serveConnection(std::shared_ptr client) const { + const string logprefix = d_logprefix + "<" + to_string(getUniqueID()) + "> "; + + HttpRequest req(logprefix); + HttpResponse resp; + ComboAddress remote; + string reply; + try { - while(!req.complete) { - int bytes = arecvtcp(data, 16384, client.get(), true); - if (bytes > 0) { - req.complete = yarl.feed(data); + YaHTTP::AsyncRequestLoader yarl; + yarl.initialize(&req); + client->setNonBlocking(); + + string data; + try { + while(!req.complete) { + int bytes = arecvtcp(data, 16384, client.get(), true); + if (bytes > 0) { + req.complete = yarl.feed(data); + } else { + // read error OR EOF + break; + } + } + yarl.finalize(); + } catch (YaHTTP::ParseError &e) { + // request stays incomplete + } + + if (d_loglevel >= WebServer::LogLevel::None) { + client->getRemote(remote); + } + + if (d_loglevel >= WebServer::LogLevel::Detailed) { + g_log<= WebServer::LogLevel::Detailed) { + g_log<= WebServer::LogLevel::Normal) { + g_log<