HTTPServer/GETHandler.cpp

50 lines
1.7 KiB
C++
Raw Permalink Normal View History

2025-06-20 02:01:27 +00:00
#include "GETHandler.h"
2022-06-29 11:38:44 -07:00
#include "HTTPParameters.h"
#include "HTTPSession.h"
#include "HTTPServer.h"
#include "HTTPRequest.h"
#include "ZString.h"
#include "IMFFormData.h"
#include "Exception.h"
#include "Log.h"
namespace http {
2025-06-20 02:01:27 +00:00
int GETHandler::processCommand(coreutils::ZString &request, core::TCPSession &session) {
2022-06-29 11:38:44 -07:00
HTTPRequest httpRequest(request);
2024-08-22 16:13:12 -07:00
HTTPSession *httpSession = static_cast<HTTPServer *>(session.server)->httpSessions.findSessionByHeader(httpRequest);
2022-06-29 11:38:44 -07:00
std::stringstream content;
2024-08-22 16:13:12 -07:00
HTTPParameters p(httpRequest, session, *httpSession, content, ((HTTPServer *)session.server)->actionList);
2022-06-29 11:38:44 -07:00
2024-07-09 20:21:46 -07:00
// TODO: What should we do if we receive a request on a GET and there is a session variable?
// If its an entry point then is it an image or link to a downloadable content that was issued
2024-07-16 16:50:20 -07:00
// by the page? Referer must point to the proper entity.
//
// DOCUMENT: The root entry point should always be a GET request to root page.
2024-07-09 20:21:46 -07:00
2024-07-16 16:50:20 -07:00
// entryPoints.processCommand(p);
2024-07-09 20:21:46 -07:00
// TODO: Right here we need to do a lookup to the entry table. File requests need an entry point URL to serve.
// TODO: Allow entry points to specify pages in the page cache or do we treat pages as automatic entry points.
2022-06-29 11:38:44 -07:00
try {
2024-08-22 16:13:12 -07:00
static_cast<HTTPServer *>(session.server)->pageList.processRequest(p);
2022-06-29 11:38:44 -07:00
httpRequest.response.setCode("200");
httpRequest.response.setText("OK");
}
catch(coreutils::Exception e) {
httpRequest.response.setCode("404");
httpRequest.response.setText("Not Found");
}
session.out << httpRequest.response.getResponse(content).str();
2024-07-09 20:21:46 -07:00
2022-06-29 11:38:44 -07:00
return true;
}
}