HTTPServer/HTTPHandler.cpp
2019-05-31 14:25:19 -07:00

38 lines
1.1 KiB
C++

#include "HTTPHandler.h"
#include "HTTPSession.h"
#include "HTTPService.h"
#include "Log.h"
namespace http {
int HTTPHandler::processCommand(std::string request, core::Session *session, std::stringstream &data) {
core::Header header(request);
core::Response response;
core::Log(core::LOG_DEBUG_1) << "Request: " << request;
HTTPSession *httpSession = ((HTTPService &)session->service).httpSessions.findSessionByHeader(header, response);
std::stringstream content;
if(((HTTPService &)session->service).pageList.processRequest(header.getPath() + " ", session, httpSession, content)) {
response.setProtocol(header.requestProtocol());
response.setCode("200");
response.setText("OK");
response.setMimeType("text/html");
data << response.getResponse(content.str());
}
else {
response.setProtocol(header.requestProtocol());
response.setCode("404");
response.setText("Not Found");
response.setMimeType("text/html");
data << response.getResponse(content.str());
}
return true;
}
}