From b7bcc401e70c7992beee1f5835f1b8eb583f1270 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 8 Jun 2012 10:12:42 +0200 Subject: [PATCH] Print user agent into log --- Server/BasicDatastructures.h | 1 + Server/RequestHandler.h | 2 +- Server/RequestParser.h | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Server/BasicDatastructures.h b/Server/BasicDatastructures.h index a788921ce..c01d5d34a 100644 --- a/Server/BasicDatastructures.h +++ b/Server/BasicDatastructures.h @@ -53,6 +53,7 @@ enum CompressionType { struct Request { std::string uri; std::string referrer; + std::string agent; boost::asio::ip::address endpoint; }; diff --git a/Server/RequestHandler.h b/Server/RequestHandler.h index 081f4260c..088376fa1 100644 --- a/Server/RequestHandler.h +++ b/Server/RequestHandler.h @@ -58,7 +58,7 @@ public: Tm=localtime(<ime); INFO((Tm->tm_mday < 10 ? "0" : "" ) << Tm->tm_mday << "-" << (Tm->tm_mon < 10 ? "0" : "" ) << Tm->tm_mon << "-" << 1900+Tm->tm_year << " " << (Tm->tm_hour < 10 ? "0" : "" ) << Tm->tm_hour << ":" << (Tm->tm_min < 10 ? "0" : "" ) << Tm->tm_min << ":" << (Tm->tm_sec < 10 ? "0" : "" ) << Tm->tm_sec << " " << - req.endpoint.to_string() << " " << req.referrer << " " << request ); + req.endpoint.to_string() << " " << req.referrer << ( 0 == req.referrer.length() ? "- " :" ") << req.agent << ( 0 == req.agent.length() ? "- " :" ") << request ); std::string command; std::size_t firstAmpPosition = request.find_first_of("?"); command = request.substr(1,firstAmpPosition-1); diff --git a/Server/RequestParser.h b/Server/RequestParser.h index c501eb2e2..7e33f9e09 100644 --- a/Server/RequestParser.h +++ b/Server/RequestParser.h @@ -164,9 +164,12 @@ private: *compressionType = gzipRFC1952; } - if(header.name == "Referer") + if("Referer" == header.name) req.referrer = header.value; + if("User-Agent" == header.name) + req.agent = header.value; + if (input == '\r') { state_ = expecting_newline_3; return boost::indeterminate;