55 lines
1.6 KiB
C++
55 lines
1.6 KiB
C++
#include "HTTPHandler.h"
|
|
#include "HTTPSession.h"
|
|
#include "HTTPServer.h"
|
|
#include "HTTPRequest.h"
|
|
#include "PString.h"
|
|
#include "IMFFormData.h"
|
|
#include "Log.h"
|
|
|
|
namespace http {
|
|
|
|
int HTTPHandler::processCommand(std::string request, core::TCPSession *session, std::stringstream &data) {
|
|
|
|
coreutils::Log(coreutils::LOG_DEBUG_4) << "DATA[" << request << "]";
|
|
|
|
if(mode == REQUEST) {
|
|
|
|
coreutils::PString request1(request);
|
|
HTTPRequest httpRequest(request1);
|
|
|
|
HTTPSession *httpSession = static_cast<HTTPServer &>(session->server).httpSessions.findSessionByHeader(httpRequest);
|
|
|
|
std::stringstream content;
|
|
|
|
if(static_cast<HTTPServer &>(session->server).pageList.processRequest(httpRequest, session, httpSession, content)) {
|
|
std::string contentType = httpRequest.getHeader("Content-Type");
|
|
if(contentType == "multipart/form-data") {
|
|
coreutils::IMFFormData *formdata = (coreutils::IMFFormData *)httpRequest.getBody();
|
|
coreutils::Log(coreutils::LOG_DEBUG_2) << "username is '" << formdata->getByName("username") << "'";
|
|
}
|
|
|
|
httpRequest.response.setCode("200");
|
|
httpRequest.response.setText("OK");
|
|
data << httpRequest.response.getResponse(content.str());
|
|
}
|
|
|
|
else {
|
|
httpRequest.response.setCode("404");
|
|
httpRequest.response.setText("Not Found");
|
|
data << httpRequest.response.getResponse(content.str());
|
|
}
|
|
|
|
grabInput();
|
|
mode = IMFHEADER;
|
|
}
|
|
else if(mode == IMFHEADER) {
|
|
HTTPHeader header(content);
|
|
releaseGrab();
|
|
mode = REQUEST;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|