Browse Source

+ HTTPConnection::SendError()

pull/475/head
hagen 9 years ago
parent
commit
3f9d2601b4
  1. 13
      HTTPServer.cpp
  2. 1
      HTTPServer.h

13
HTTPServer.cpp

@ -813,7 +813,7 @@ namespace util @@ -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 @@ -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 @@ -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 @@ -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))

1
HTTPServer.h

@ -59,6 +59,7 @@ namespace util @@ -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);

Loading…
Cancel
Save