57 lines
1.9 KiB
C++
57 lines
1.9 KiB
C++
#include "HTTPHandler.h"
|
|
#include "HTTPSession.h"
|
|
#include "HTTPServer.h"
|
|
#include "HTTPRequest.h"
|
|
#include "ZString.h"
|
|
#include "IMFFormData.h"
|
|
#include "Log.h"
|
|
|
|
namespace http {
|
|
|
|
int HTTPHandler::processCommand(coreutils::ZString &request, core::TCPSession &session) {
|
|
if(!httpRequest) {
|
|
httpRequest = new HTTPRequest(request);
|
|
// session->server.commands.grabInput(session, *this);
|
|
processHTTPRequest(session);
|
|
}
|
|
else {
|
|
// httpRequest->parse(request1);
|
|
if(!request.equals("")) {
|
|
// session->server.commands.clearGrab(session);
|
|
processHTTPRequest(session);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool HTTPHandler::processHTTPRequest(core::TCPSession &session) {
|
|
|
|
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)) {
|
|
|
|
coreutils::ZString contentType = httpRequest->getHeader("Content-Type");
|
|
if(contentType.equals("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");
|
|
session.out << httpRequest->response.getResponse(content).str();
|
|
coreutils::Log(coreutils::LOG_DEBUG_1) << "Sending response to client..." << content.str();
|
|
}
|
|
else {
|
|
httpRequest->response.setCode("404");
|
|
httpRequest->response.setText("Not Found");
|
|
session.out << httpRequest->response.getResponse(content).str();
|
|
}
|
|
delete httpRequest;
|
|
httpRequest = NULL;
|
|
return true;
|
|
}
|
|
|
|
}
|