Browse Source

Prepare support for POST/PUT

pull/93/head
Mikal Villa 10 years ago
parent
commit
bff3d8f5c1
  1. 14
      HTTPServer.cpp
  2. 2
      HTTPServer.h

14
HTTPServer.cpp

@ -323,8 +323,12 @@ namespace util
} }
s << "<p><a href=\"zmw2cyw2vj7f6obx3msmdvdepdhnw2ctc4okza2zjxlukkdfckhq\">Flibusta</a></p>"; s << "<p><a href=\"zmw2cyw2vj7f6obx3msmdvdepdhnw2ctc4okza2zjxlukkdfckhq\">Flibusta</a></p>";
} }
void HTTPConnection::HandleDestinationRequest (const std::string& address, const std::string& uri) void HTTPConnection::HandleDestinationRequest (const std::string& address, const std::string& uri)
{
HandleDestinationRequest(address, "GET", "", uri);
}
void HTTPConnection::HandleDestinationRequest (const std::string& address, const std::string& method, const std::string& data, const std::string& uri)
{ {
i2p::data::IdentHash destination; i2p::data::IdentHash destination;
std::string fullAddress; std::string fullAddress;
@ -380,7 +384,13 @@ namespace util
m_Stream = i2p::stream::CreateStream (*leaseSet); m_Stream = i2p::stream::CreateStream (*leaseSet);
if (m_Stream) if (m_Stream)
{ {
std::string request = "GET " + uri + " HTTP/1.1\n Host:" + fullAddress + "\n"; std::string request = method+" " + uri + " HTTP/1.1\n Host:" + fullAddress + "\r\n";
if (!strcmp(method.c_str(), "GET"))
{
// POST/PUT, apply body
request += "\r\n"+ data;
}
LogPrint("HTTP Client Request: ", request);
m_Stream->Send ((uint8_t *)request.c_str (), request.length (), 10); m_Stream->Send ((uint8_t *)request.c_str (), request.length (), 10);
AsyncStreamReceive (); AsyncStreamReceive ();
} }

2
HTTPServer.h

@ -69,7 +69,9 @@ namespace util
protected: protected:
virtual void HandleDestinationRequest(const std::string& address, const std::string& uri); virtual void HandleDestinationRequest(const std::string& address, const std::string& uri);
virtual void HandleDestinationRequest(const std::string& address, const std::string& method, const std::string& data, const std::string& uri);
virtual void RunRequest (); virtual void RunRequest ();
private: private:

Loading…
Cancel
Save