mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
add http connect to http proxy (untested)
This commit is contained in:
parent
c1dbd3ffd0
commit
b2d1962b81
|
@ -67,6 +67,8 @@ namespace proxy {
|
|||
void ForwardToUpstreamProxy();
|
||||
void HandleUpstreamHTTPProxyConnect(const boost::system::error_code & ec);
|
||||
void HandleUpstreamSocksProxyConnect(const boost::system::error_code & ec);
|
||||
void HTTPConnect(const std::string & host, uint16_t port);
|
||||
void HandleHTTPConnectStreamRequestComplete(std::shared_ptr<i2p::stream::Stream> stream);
|
||||
|
||||
void HandleSocksProxySendHandshake(const boost::system::error_code & ec, std::size_t bytes_transfered);
|
||||
void HandleSocksProxyReply(const boost::system::error_code & ec, std::size_t bytes_transfered);
|
||||
|
@ -257,11 +259,31 @@ namespace proxy {
|
|||
GenericProxyInfo("Addresshelper found", ss.str().c_str());
|
||||
return true; /* request processed */
|
||||
}
|
||||
|
||||
std::string dest_host;
|
||||
uint16_t dest_port;
|
||||
bool useConnect = false;
|
||||
if(m_ClientRequest.method == "CONNECT")
|
||||
{
|
||||
std::string uri(m_ClientRequest.uri);
|
||||
auto pos = uri.find(":");
|
||||
if(pos == std::string::npos || pos == uri.size() - 1)
|
||||
{
|
||||
GenericProxyError("Invalid Request", "invalid request uri");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
useConnect = true;
|
||||
dest_port = std::stoi(uri.substr(pos+1));
|
||||
dest_host = uri.substr(0, pos);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SanitizeHTTPRequest(m_ClientRequest);
|
||||
|
||||
std::string dest_host = m_RequestURL.host;
|
||||
uint16_t dest_port = m_RequestURL.port;
|
||||
dest_host = m_RequestURL.host;
|
||||
dest_port = m_RequestURL.port;
|
||||
/* always set port, even if missing in request */
|
||||
if (!dest_port)
|
||||
dest_port = (m_RequestURL.schema == "https") ? 443 : 80;
|
||||
|
@ -293,7 +315,7 @@ namespace proxy {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* check dest_host really exists and inside I2P network */
|
||||
i2p::data::IdentHash identHash;
|
||||
if (str_rmatch(dest_host, ".i2p")) {
|
||||
|
@ -316,6 +338,11 @@ namespace proxy {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
if(useConnect)
|
||||
{
|
||||
HTTPConnect(dest_host, dest_port);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* make relative url */
|
||||
m_RequestURL.schema = "";
|
||||
|
@ -427,6 +454,43 @@ namespace proxy {
|
|||
Terminate();
|
||||
}
|
||||
|
||||
void HTTPReqHandler::HTTPConnect(const std::string & host, uint16_t port)
|
||||
{
|
||||
std::string hostname(host);
|
||||
if(str_rmatch(hostname, ".i2p"))
|
||||
GetOwner()->CreateStream (std::bind (&HTTPReqHandler::HandleHTTPConnectStreamRequestComplete,
|
||||
shared_from_this(), std::placeholders::_1), host, port);
|
||||
else
|
||||
ForwardToUpstreamProxy();
|
||||
}
|
||||
|
||||
void HTTPReqHandler::HandleHTTPConnectStreamRequestComplete(std::shared_ptr<i2p::stream::Stream> stream)
|
||||
{
|
||||
if(stream)
|
||||
{
|
||||
m_ClientResponse.code = 101;
|
||||
m_ClientResponse.status = "Switching Protocols";
|
||||
m_send_buf = m_ClientResponse.to_string();
|
||||
boost::asio::async_write(*m_sock, boost::asio::buffer(m_send_buf), boost::asio::transfer_all(), [&] (const boost::system::error_code & ec, std::size_t transferred) {
|
||||
if(ec)
|
||||
{
|
||||
LogPrint(eLogError, "HTTPProxy: failed to send reply: ", ec.message());
|
||||
}
|
||||
else
|
||||
{
|
||||
auto connection = std::make_shared<i2p::client::I2PTunnelConnection>(GetOwner(), m_sock, stream);
|
||||
GetOwner()->AddHandler(connection);
|
||||
connection->I2PConnect();
|
||||
}
|
||||
Done(shared_from_this());
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
GenericProxyError("CONNECT error", "Failed to Connect");
|
||||
}
|
||||
}
|
||||
|
||||
void HTTPReqHandler::SocksProxySuccess()
|
||||
{
|
||||
if(m_ClientRequest.method == "CONNECT") {
|
||||
|
|
Loading…
Reference in a new issue