From f10064ce39a8deea81d6c5157a5d3177fdfd71bc Mon Sep 17 00:00:00 2001 From: hagen Date: Tue, 24 May 2016 00:00:00 +0000 Subject: [PATCH] * HTTPServer.cpp : update response building --- HTTPServer.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 4e44e6f9..5d54711d 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -749,7 +748,7 @@ namespace http { if (needAuth && !CheckAuth(req)) { res.code = 401; - res.headers.insert(std::pair("WWW-Authenticate", "Basic realm=\"WebAdmin\"")); + res.add_header("WWW-Authenticate", "Basic realm=\"WebAdmin\""); SendReply(res, content); return; } @@ -763,6 +762,8 @@ namespace http { else ShowStatus (s); ShowPageTail (s); + + res.code = 200; content = s.str (); SendReply (res, content); } @@ -845,21 +846,11 @@ namespace http { void HTTPConnection::SendReply (HTTPRes& reply, std::string& content) { - std::time_t time_now = std::time(nullptr); - char time_buff[128]; - std::strftime(time_buff, sizeof(time_buff), "%a, %d %b %Y %H:%M:%S GMT", std::gmtime(&time_now)); - reply.status = HTTPCodeToStatus(reply.code); - reply.headers.insert(std::pair("Date", time_buff)); - reply.headers.insert(std::pair("Content-Type", "text/html")); - reply.headers.insert(std::pair("Content-Length", std::to_string(content.size()))); + reply.add_header("Content-Type", "text/html"); + reply.body = content; std::string res = reply.to_string(); - std::vector buffers; - - buffers.push_back(boost::asio::buffer(res)); - buffers.push_back(boost::asio::buffer(content)); - - boost::asio::async_write (*m_Socket, buffers, + boost::asio::async_write (*m_Socket, boost::asio::buffer(res), std::bind (&HTTPConnection::Terminate, shared_from_this (), std::placeholders::_1)); }