HTTPServer/HTTPHandler.cpp

34 lines
1008 B
C++

#include "HTTPHandler.h"
#include "HTTPSession.h"
#include "HTTPService.h"
#include "HTTPRequest.h"
#include "PString.h"
#include "Log.h"
namespace http {
int HTTPHandler::processCommand(std::string request, core::Session *session, std::stringstream &data) {
coreutils::PString request1(request);
HTTPRequest httpRequest(request1);
HTTPSession *httpSession = ((HTTPService &)session->service).httpSessions.findSessionByHeader(httpRequest);
std::stringstream content;
if(((HTTPService &)session->service).pageList.processRequest(httpRequest, session, httpSession, content)) {
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());
}
return true;
}
}