From 07c6f2a20bc6428e3b35f1fa6e7fd6fb23169595 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 16 Jan 2015 16:51:52 -0500 Subject: [PATCH] make HTTP header if necessary --- I2PControl.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/I2PControl.cpp b/I2PControl.cpp index 30efc9bd..e8f98cbe 100644 --- a/I2PControl.cpp +++ b/I2PControl.cpp @@ -2,6 +2,8 @@ #include #include +#include +#include #include #include #include "Log.h" @@ -185,8 +187,23 @@ namespace client std::ostringstream ss; boost::property_tree::write_json (ss, pt, false); - size_t len = ss.str ().length (); - memcpy (buf->data (), ss.str ().c_str (), len); + size_t len = ss.str ().length (), offset = 0; + if (isHtml) + { + std::ostringstream header; + header << "HTTP/1.1 200 OK\r\n"; + header << "Connection: close\r\n"; + header << "Content-Length: " << boost::lexical_cast(len) << "\r\n"; + header << "Content-Type: application/json\r\n"; + header << "Date: "; + auto facet = new boost::local_time::local_time_facet ("%a, %d %b %Y %H:%M:%S GMT"); + header.imbue(std::locale (header.getloc(), facet)); + header << boost::posix_time::second_clock::local_time() << "\r\n"; + header << "\r\n"; + offset = header.str ().size (); + memcpy (buf->data (), header.str ().c_str (), offset); + } + memcpy (buf->data () + offset, ss.str ().c_str (), len); boost::asio::async_write (*socket, boost::asio::buffer (buf->data (), len), boost::asio::transfer_all (), std::bind(&I2PControlService::HandleResponseSent, this,