Browse Source

skip HTTP header

pull/150/head
orignal 10 years ago
parent
commit
514947ba49
  1. 16
      I2PControl.cpp
  2. 2
      I2PControl.h

16
I2PControl.cpp

@ -125,8 +125,20 @@ namespace client
{ {
try try
{ {
bool isHtml = !memcmp (buf->data (), "POST", 4);
std::stringstream ss; std::stringstream ss;
ss.write (buf->data (), bytes_transferred); ss.write (buf->data (), bytes_transferred);
if (isHtml)
{
std::string header;
while (!ss.eof () && header != "\r")
std::getline(ss, header);
if (ss.eof ())
{
LogPrint (eLogError, "Malformed I2PControl request. HTTP header expected");
return; // TODO:
}
}
boost::property_tree::ptree pt; boost::property_tree::ptree pt;
boost::property_tree::read_json (ss, pt); boost::property_tree::read_json (ss, pt);
std::string method = pt.get<std::string>(I2P_CONTROL_PROPERTY_METHOD); std::string method = pt.get<std::string>(I2P_CONTROL_PROPERTY_METHOD);
@ -142,7 +154,7 @@ namespace client
} }
std::map<std::string, std::string> results; std::map<std::string, std::string> results;
(this->*(it->second))(params, results); (this->*(it->second))(params, results);
SendResponse (socket, buf, pt.get<std::string>(I2P_CONTROL_PROPERTY_ID), results); SendResponse (socket, buf, pt.get<std::string>(I2P_CONTROL_PROPERTY_ID), results, isHtml);
} }
else else
LogPrint (eLogWarning, "Unknown I2PControl method ", method); LogPrint (eLogWarning, "Unknown I2PControl method ", method);
@ -160,7 +172,7 @@ namespace client
void I2PControlService::SendResponse (std::shared_ptr<boost::asio::ip::tcp::socket> socket, void I2PControlService::SendResponse (std::shared_ptr<boost::asio::ip::tcp::socket> socket,
std::shared_ptr<I2PControlBuffer> buf, const std::string& id, std::shared_ptr<I2PControlBuffer> buf, const std::string& id,
const std::map<std::string, std::string>& results) const std::map<std::string, std::string>& results, bool isHtml)
{ {
boost::property_tree::ptree ptr; boost::property_tree::ptree ptr;
for (auto& result: results) for (auto& result: results)

2
I2PControl.h

@ -72,7 +72,7 @@ namespace client
std::shared_ptr<boost::asio::ip::tcp::socket> socket, std::shared_ptr<I2PControlBuffer> buf); std::shared_ptr<boost::asio::ip::tcp::socket> socket, std::shared_ptr<I2PControlBuffer> buf);
void SendResponse (std::shared_ptr<boost::asio::ip::tcp::socket> socket, void SendResponse (std::shared_ptr<boost::asio::ip::tcp::socket> socket,
std::shared_ptr<I2PControlBuffer> buf, const std::string& id, std::shared_ptr<I2PControlBuffer> buf, const std::string& id,
const std::map<std::string, std::string>& results); const std::map<std::string, std::string>& results, bool isHtml);
void HandleResponseSent (const boost::system::error_code& ecode, std::size_t bytes_transferred, void HandleResponseSent (const boost::system::error_code& ecode, std::size_t bytes_transferred,
std::shared_ptr<boost::asio::ip::tcp::socket> socket, std::shared_ptr<I2PControlBuffer> buf); std::shared_ptr<boost::asio::ip::tcp::socket> socket, std::shared_ptr<I2PControlBuffer> buf);

Loading…
Cancel
Save