From 727068cc4bf9336945e5f611f750031c0d79af0e Mon Sep 17 00:00:00 2001 From: hagen Date: Mon, 27 Jun 2016 01:30:00 +0000 Subject: [PATCH] * HTTPProxy.cpp : migrate HTTPRequestFailed() to new http classes --- HTTPProxy.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/HTTPProxy.cpp b/HTTPProxy.cpp index ed41049a..af914b47 100644 --- a/HTTPProxy.cpp +++ b/HTTPProxy.cpp @@ -106,14 +106,13 @@ namespace proxy { //TODO: handle this apropriately void HTTPReqHandler::HTTPRequestFailed(const char *message) { - std::size_t size = std::strlen(message); - std::stringstream ss; - ss << "HTTP/1.0 500 Internal Server Error\r\n" - << "Content-Type: text/plain\r\n"; - ss << "Content-Length: " << std::to_string(size + 2) << "\r\n" - << "\r\n"; /* end of headers */ - ss << message << "\r\n"; - std::string response = ss.str(); + i2p::http::HTTPRes res; + res.code = 500; + res.add_header("Content-Type", "text/plain"); + res.add_header("Connection", "close"); + res.body = message; + res.body += "\r\n"; + std::string response = res.to_string(); boost::asio::async_write(*m_sock, boost::asio::buffer(response), std::bind(&HTTPReqHandler::SentHTTPFailed, shared_from_this(), std::placeholders::_1)); }