mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-31 00:34:20 +00:00
read Content-Length from http header
This commit is contained in:
parent
9e2a770a26
commit
885d57138a
@ -151,7 +151,7 @@ namespace client
|
|||||||
void I2PControlService::ReadRequest (std::shared_ptr<ssl_socket> socket)
|
void I2PControlService::ReadRequest (std::shared_ptr<ssl_socket> socket)
|
||||||
{
|
{
|
||||||
auto request = std::make_shared<I2PControlBuffer>();
|
auto request = std::make_shared<I2PControlBuffer>();
|
||||||
boost::asio::async_read (*socket,
|
socket->async_read_some (
|
||||||
#if BOOST_VERSION >= 104900
|
#if BOOST_VERSION >= 104900
|
||||||
boost::asio::buffer (*request),
|
boost::asio::buffer (*request),
|
||||||
#else
|
#else
|
||||||
@ -179,13 +179,25 @@ namespace client
|
|||||||
if (isHtml)
|
if (isHtml)
|
||||||
{
|
{
|
||||||
std::string header;
|
std::string header;
|
||||||
|
size_t contentLength = 0;
|
||||||
while (!ss.eof () && header != "\r")
|
while (!ss.eof () && header != "\r")
|
||||||
|
{
|
||||||
std::getline(ss, header);
|
std::getline(ss, header);
|
||||||
|
auto colon = header.find (':');
|
||||||
|
if (colon != std::string::npos && header.substr (0, colon) == "Content-Length")
|
||||||
|
contentLength = std::stoi (header.substr (colon + 1));
|
||||||
|
}
|
||||||
if (ss.eof ())
|
if (ss.eof ())
|
||||||
{
|
{
|
||||||
LogPrint (eLogError, "Malformed I2PControl request. HTTP header expected");
|
LogPrint (eLogError, "Malformed I2PControl request. HTTP header expected");
|
||||||
return; // TODO:
|
return; // TODO:
|
||||||
}
|
}
|
||||||
|
ssize_t rem = contentLength + ss.tellg () - bytes_transferred; // more bytes to read
|
||||||
|
if (rem > 0)
|
||||||
|
{
|
||||||
|
bytes_transferred = boost::asio::read (*socket, boost::asio::buffer (buf->data (), rem));
|
||||||
|
ss.write (buf->data (), bytes_transferred);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#if GCC47_BOOST149
|
#if GCC47_BOOST149
|
||||||
LogPrint (eLogError, "json_read is not supported due bug in boost 1.49 with gcc 4.7");
|
LogPrint (eLogError, "json_read is not supported due bug in boost 1.49 with gcc 4.7");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user