From 124007dc313091de4725bfbb84f2ab65e8194194 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 12 Sep 2014 18:36:56 -0400 Subject: [PATCH] Content-Type for POST --- HTTPProxy.cpp | 9 ++++++--- HTTPServer.cpp | 18 +++++++++--------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/HTTPProxy.cpp b/HTTPProxy.cpp index 22365357..82c0662d 100644 --- a/HTTPProxy.cpp +++ b/HTTPProxy.cpp @@ -63,9 +63,12 @@ namespace proxy request r; ExtractRequest(r); parseHeaders(m_Buffer, r.headers); - const char * data = strstr (m_Buffer, "\r\n\r\n"); - if (data) data += 4; - + const char * data = nullptr; + if (r.method == "POST") + { + data = strstr (m_Buffer, "\r\n\r\n"); + if (data) data += 4; + } LogPrint("Requesting ", r.host, " with path ", r.uri, " and method ", r.method); HandleDestinationRequest(r.host, r.method, data ? std::string (data) : "" , r.uri); } diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 35bb60d6..5405325a 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -760,15 +760,15 @@ namespace util m_Stream = i2p::stream::CreateStream (*leaseSet); if (m_Stream) { - std::string request = method+" " + uri + " HTTP/1.1\n Host:" + fullAddress + "\r\n"; - if (!strcmp(method.c_str(), "GET") && data.size () > 0) - { - // POST/PUT, apply body - request += "Content-Length: " ; - request += data.size (); - request += "\r\n\r\n" + data; - } - LogPrint("HTTP Client Request: ", request); + std::string request = method + " " + uri + " HTTP/1.1\r\nHost:" + fullAddress + "\r\n"; + if (method == "POST" && data.size () > 0) + { + // POST/PUT, apply body + request += "Content-Type: application/x-www-form-urlencoded\r\n"; + request += "Content-Length: " + boost::lexical_cast(data.size ()) + "\r\n"; + request += "\r\n" + data; + } + LogPrint("HTTP Client Request: ", request); m_Stream->Send ((uint8_t *)request.c_str (), request.size (), 10); AsyncStreamReceive (); }