+ HTTPConnection::SendError()

This commit is contained in:
hagen 2016-04-14 00:00:00 +00:00
parent 04bfd52fba
commit 3f9d2601b4
2 changed files with 10 additions and 4 deletions

View File

@ -813,7 +813,7 @@ namespace util
if (!i2p::client::context.GetAddressBook ().GetIdentHash (address, destination))
{
LogPrint (eLogWarning, "HTTPServer: Unknown address ", address);
SendReply ("<html>" + itoopieImage + "<br>\r\nUnknown address " + address + "</html>", 404);
SendError ("Unknown address " + address);
return;
}
@ -840,9 +840,9 @@ namespace util
if (leaseSet && !leaseSet->IsExpired ()) {
SendToDestination (leaseSet, port, buf, len);
} else if (leaseSet) {
SendReply ("<html>" + itoopieImage + "<br>\r\nLeaseSet expired</html>", 504);
SendError ("LeaseSet expired");
} else {
SendReply ("<html>" + itoopieImage + "<br>\r\nLeaseSet not found</html>", 504);
SendError ("LeaseSet not found");
}
}
}
@ -877,7 +877,7 @@ namespace util
else
{
if (ecode == boost::asio::error::timed_out)
SendReply ("<html>" + itoopieImage + "<br>\r\nNot responding</html>", 504);
SendError ("Host not responding");
else if (ecode != boost::asio::error::operation_aborted)
Terminate ();
}
@ -905,6 +905,11 @@ namespace util
std::bind (&HTTPConnection::HandleWriteReply, shared_from_this (), std::placeholders::_1));
}
void HTTPConnection::SendError(const std::string& content)
{
SendReply ("<html>" + itoopieImage + "<br>\r\n" + content + "</html>", 504);
}
HTTPServer::HTTPServer (const std::string& address, int port):
m_Thread (nullptr), m_Work (m_Service),
m_Acceptor (m_Service, boost::asio::ip::tcp::endpoint (boost::asio::ip::address::from_string(address), port))

View File

@ -59,6 +59,7 @@ namespace util
void HandleWriteReply(const boost::system::error_code& ecode);
void HandleWrite (const boost::system::error_code& ecode);
void SendReply (const std::string& content, int status = 200);
void SendError (const std::string& message);
void HandleRequest (const std::string& address);
void HandleCommand (const std::string& command, std::stringstream& s);