Skip to content
/ i2pd Public
forked from PurpleI2P/i2pd

Commit

Permalink
replace Host: for server http tunnels
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Jun 3, 2015
1 parent d7deb93 commit 09fd0ba
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
32 changes: 27 additions & 5 deletions I2PTunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ namespace client
I2PTunnelConnectionHTTP::I2PTunnelConnectionHTTP (I2PService * owner, std::shared_ptr<i2p::stream::Stream> stream,
std::shared_ptr<boost::asio::ip::tcp::socket> socket,
const boost::asio::ip::tcp::endpoint& target, const std::string& host):
I2PTunnelConnection (owner, stream, socket, target), m_HeaderSent (false)
I2PTunnelConnection (owner, stream, socket, target), m_Host (host), m_HeaderSent (false)
{
}

Expand All @@ -174,10 +174,32 @@ namespace client
if (m_HeaderSent)
I2PTunnelConnection::Write (buf, len);
else
{
m_Header.write ((const char *)buf, len);
I2PTunnelConnection::Write ((uint8_t *)m_Header.str ().c_str (), m_Header.str ().length ());
m_HeaderSent = true;
{
m_InHeader.clear ();
m_InHeader.write ((const char *)buf, len);
std::string line;
bool endOfHeader = false;
while (!endOfHeader)
{
std::getline(m_InHeader, line);
if (!m_InHeader.fail ())
{
if (line.find ("Host:") != std::string::npos)
m_OutHeader << "Host: " << m_Host << "\r\n";
else
m_OutHeader << line << "\n";
if (line == "\r") endOfHeader = true;
}
else
break;
}

if (endOfHeader)
{
m_OutHeader << m_InHeader.str (); // data right after header
m_HeaderSent = true;
I2PTunnelConnection::Write ((uint8_t *)m_OutHeader.str ().c_str (), m_OutHeader.str ().length ());
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion I2PTunnel.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ namespace client

private:

std::stringstream m_Header;
std::string m_Host;
std::stringstream m_InHeader, m_OutHeader;
bool m_HeaderSent;
};

Expand Down

0 comments on commit 09fd0ba

Please sign in to comment.