mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
fixed POST methos
This commit is contained in:
parent
5ea3e70c3a
commit
86fdd48229
@ -30,7 +30,7 @@ namespace proxy
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPProxyConnection::ExtractRequest(request &m_Request)
|
void HTTPProxyConnection::ExtractRequest(request& r)
|
||||||
{
|
{
|
||||||
std::string requestString = m_Buffer;
|
std::string requestString = m_Buffer;
|
||||||
int idx=requestString.find(" ");
|
int idx=requestString.find(" ");
|
||||||
@ -52,72 +52,28 @@ namespace proxy
|
|||||||
path=m[4].str();
|
path=m[4].str();
|
||||||
}
|
}
|
||||||
LogPrint("server is: ",server, "\n path is: ",path);
|
LogPrint("server is: ",server, "\n path is: ",path);
|
||||||
m_Request.uri = path;
|
r.uri = path;
|
||||||
m_Request.method = method;
|
r.method = method;
|
||||||
m_Request.host = server;
|
r.host = server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HTTPProxyConnection::RunRequest()
|
void HTTPProxyConnection::RunRequest()
|
||||||
{
|
{
|
||||||
request m_Request;
|
request r;
|
||||||
ExtractRequest(m_Request);
|
ExtractRequest(r);
|
||||||
parseHeaders(m_Buffer, m_Request.headers);
|
parseHeaders(m_Buffer, r.headers);
|
||||||
|
size_t len = 0;
|
||||||
LogPrint("Requesting ", m_Request.host, " with path ", m_Request.uri, " and method ", m_Request.method);
|
const char * data = strstr (m_Buffer, "\r\n\r\n");
|
||||||
HandleDestinationRequest(m_Request.host, m_Request.uri);
|
if (data)
|
||||||
|
{
|
||||||
|
data += 4;
|
||||||
|
len = strlen (m_Buffer) - (data - m_Buffer);
|
||||||
|
}
|
||||||
|
LogPrint("Requesting ", r.host, " with path ", r.uri, " and method ", r.method);
|
||||||
|
HandleDestinationRequest(r.host, r.method, len > 0 ? std::string (data, len) : "" , r.uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
//void HTTPConnection::HandleDestinationRequest (const std::string& address, const std::string& uri)
|
|
||||||
//{
|
|
||||||
// i2p::data::IdentHash destination;
|
|
||||||
// std::string fullAddress;
|
|
||||||
// if (address.find (".b32.i2p") != std::string::npos)
|
|
||||||
// {
|
|
||||||
// int li = address.find_first_of (".");
|
|
||||||
// std::string newaddress = address.substr (0, li);
|
|
||||||
// if (i2p::data::Base32ToByteStream (newaddress.c_str (), newaddress.length (), (uint8_t *)destination, 32) != 32)
|
|
||||||
// {
|
|
||||||
// LogPrint ("Invalid Base32 address ", newaddress);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// fullAddress = newaddress + ".b32.i2p";
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// auto addr = i2p::data::netdb.FindAddress (address);
|
|
||||||
// if (!addr)
|
|
||||||
// {
|
|
||||||
// LogPrint ("Unknown address ", address);
|
|
||||||
// SendReply("<html>"+ i2p::proxy::itoopieImage +"<br>Unknown address " + address + "</html>");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// destination = *addr;
|
|
||||||
// fullAddress = address;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// auto leaseSet = i2p::data::netdb.FindLeaseSet (destination);
|
|
||||||
// if (!leaseSet || !leaseSet->HasNonExpiredLeases ())
|
|
||||||
// {
|
|
||||||
// i2p::data::netdb.Subscribe(destination);
|
|
||||||
// std::this_thread::sleep_for (std::chrono::seconds(10)); // wait for 10 seconds
|
|
||||||
// leaseSet = i2p::data::netdb.FindLeaseSet (destination);
|
|
||||||
// if (!leaseSet || !leaseSet->HasNonExpiredLeases ()) // still no LeaseSet
|
|
||||||
// {
|
|
||||||
// SendReply(leaseSet ? "<html>"+ i2p::proxy::itoopieImage +"<br>Leases expired</html>" : "<html>"+ i2p::proxy::itoopieImage +"LeaseSet not found</html>");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if (!m_Stream)
|
|
||||||
// m_Stream = i2p::stream::CreateStream (*leaseSet);
|
|
||||||
// if (m_Stream)
|
|
||||||
// {
|
|
||||||
// std::string request = "GET " + uri + " HTTP/1.1\n Host:" + fullAddress + "\n";
|
|
||||||
// m_Stream->Send ((uint8_t *)request.c_str (), request.length (), 10);
|
|
||||||
// AsyncStreamReceive ();
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ namespace proxy
|
|||||||
protected:
|
protected:
|
||||||
void RunRequest();
|
void RunRequest();
|
||||||
void parseHeaders(const std::string& h, std::vector<header>& hm);
|
void parseHeaders(const std::string& h, std::vector<header>& hm);
|
||||||
void ExtractRequest(request &m_Request);
|
void ExtractRequest(request& r);
|
||||||
};
|
};
|
||||||
|
|
||||||
class HTTPProxy : public i2p::util::HTTPServer
|
class HTTPProxy : public i2p::util::HTTPServer
|
||||||
|
@ -765,7 +765,7 @@ namespace util
|
|||||||
{
|
{
|
||||||
// POST/PUT, apply body
|
// POST/PUT, apply body
|
||||||
request += "Content-Length: " ;
|
request += "Content-Length: " ;
|
||||||
request += request.size ();
|
request += data.size ();
|
||||||
request += "\r\n" + data;
|
request += "\r\n" + data;
|
||||||
}
|
}
|
||||||
LogPrint("HTTP Client Request: ", request);
|
LogPrint("HTTP Client Request: ", request);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user