diff options
author | madmaxoft <github@xoft.cz> | 2013-09-28 19:30:25 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2013-09-28 19:30:25 +0200 |
commit | 8130e6dd5439e381aae18532ede48441a4b46155 (patch) | |
tree | 679ffa469ffb3e00629128a353bd2cb2347f915f /source/HTTPServer/HTTPServer.cpp | |
parent | Added URLDecode() and ReplaceAllCharOccurrences() to StringUtils. (diff) | |
download | cuberite-8130e6dd5439e381aae18532ede48441a4b46155.tar cuberite-8130e6dd5439e381aae18532ede48441a4b46155.tar.gz cuberite-8130e6dd5439e381aae18532ede48441a4b46155.tar.bz2 cuberite-8130e6dd5439e381aae18532ede48441a4b46155.tar.lz cuberite-8130e6dd5439e381aae18532ede48441a4b46155.tar.xz cuberite-8130e6dd5439e381aae18532ede48441a4b46155.tar.zst cuberite-8130e6dd5439e381aae18532ede48441a4b46155.zip |
Diffstat (limited to 'source/HTTPServer/HTTPServer.cpp')
-rw-r--r-- | source/HTTPServer/HTTPServer.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/source/HTTPServer/HTTPServer.cpp b/source/HTTPServer/HTTPServer.cpp index 8494d6fce..86fd545f6 100644 --- a/source/HTTPServer/HTTPServer.cpp +++ b/source/HTTPServer/HTTPServer.cpp @@ -7,6 +7,7 @@ #include "HTTPServer.h" #include "HTTPMessage.h" #include "HTTPConnection.h" +#include "HTTPFormParser.h" @@ -27,18 +28,49 @@ class cDebugCallbacks : { virtual void OnRequestBegun(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) override { - // Nothing needed + if (cHTTPFormParser::HasFormData(a_Request)) + { + a_Request.SetUserData(new cHTTPFormParser(a_Request)); + } } virtual void OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, int a_Size) override { - // TODO + cHTTPFormParser * FormParser = (cHTTPFormParser *)(a_Request.GetUserData()); + if (FormParser != NULL) + { + FormParser->Parse(a_Data, a_Size); + } } virtual void OnRequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) override { + cHTTPFormParser * FormParser = (cHTTPFormParser *)(a_Request.GetUserData()); + if (FormParser != NULL) + { + if (FormParser->Finish()) + { + cHTTPResponse Resp; + Resp.SetContentType("text/html"); + a_Connection.Send(Resp); + a_Connection.Send("<html><body><table border=1 cellspacing=0><tr><th>Name</th><th>Value</th></tr>\r\n"); + for (cHTTPFormParser::iterator itr = FormParser->begin(), end = FormParser->end(); itr != end; ++itr) + { + a_Connection.Send(Printf("<tr><td valign=\"top\"><pre>%s</pre></td><td valign=\"top\"><pre>%s</pre></td></tr>\r\n", itr->first.c_str(), itr->second.c_str())); + } // for itr - FormParser[] + a_Connection.Send("</table></body></html>"); + return; + } + + // Parsing failed: + cHTTPResponse Resp; + Resp.SetContentType("text/plain"); + a_Connection.Send(Resp); + a_Connection.Send("Form parsing failed"); + } + cHTTPResponse Resp; Resp.SetContentType("text/plain"); a_Connection.Send(Resp); |