restructure + parser + readme updates

This commit is contained in:
Nicholas Orlowsky 2023-09-07 19:33:22 -04:00
parent c726e6cf28
commit b4265fe9c3
No known key found for this signature in database
GPG key ID: 24C84C4DDAD95065
10 changed files with 778 additions and 149 deletions

6
backends/backend.cpp Normal file
View file

@ -0,0 +1,6 @@
#include "../http.cpp"
class backend {
public:
virtual http_response handle_request(http_request req) {};
};

21
backends/file_backend.cpp Normal file
View file

@ -0,0 +1,21 @@
#include "backend.cpp"
class file_backend : public backend {
public:
http_response handle_request(http_request req) {
string filename = req.path() == "/" ? "index.html" : req.path();
filename = "./www/" + filename;
ifstream stream(filename);
int status = 200;
if (!stream.is_open()) {
status = 404;
filename = "./error_pages/404.html";
stream = ifstream(filename);
}
stringstream buffer;
buffer << stream.rdbuf();
return http_response(buffer.str(), status);
}
};