Browse Source

Prepare support for POST/PUT

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

16
HTTPServer.cpp

@ -323,8 +323,12 @@ namespace util @@ -323,8 +323,12 @@ namespace util
}
s << "<p><a href=\"zmw2cyw2vj7f6obx3msmdvdepdhnw2ctc4okza2zjxlukkdfckhq\">Flibusta</a></p>";
}
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;
std::string fullAddress;
@ -380,7 +384,13 @@ namespace util @@ -380,7 +384,13 @@ namespace util
m_Stream = i2p::stream::CreateStream (*leaseSet);
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);
AsyncStreamReceive ();
}
@ -421,7 +431,7 @@ namespace util @@ -421,7 +431,7 @@ namespace util
m_Reply.headers[1].value = "text/html";
boost::asio::async_write (*m_Socket, m_Reply.to_buffers(status),
boost::bind (&HTTPConnection::HandleWriteReply, this,
boost::bind (&HTTPConnection::HandleWriteReply, this,
boost::asio::placeholders::error));
}

2
HTTPServer.h

@ -69,7 +69,9 @@ namespace util @@ -69,7 +69,9 @@ namespace util
protected:
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 ();
private:

Loading…
Cancel
Save