rcpp_framework/web/http/web_root.h

59 lines
1.5 KiB
C
Raw Normal View History

#ifndef WEB_ROOT_H
#define WEB_ROOT_H
2020-11-25 00:20:41 +01:00
#include "core/containers/vector.h"
#include "mutex"
2020-11-25 00:20:41 +01:00
#include <functional>
#include <map>
#include "core/string.h"
2020-11-25 00:20:41 +01:00
#include "web_node.h"
#include "middleware.h"
2020-11-25 00:20:41 +01:00
class Request;
// TODO FileCache -> set up, for this webroot, don't use singleton
2022-01-08 10:50:07 +01:00
class WebRoot : public WebNode {
RCPP_OBJECT(WebRoot, WebNode);
2021-11-21 14:40:47 +01:00
2020-11-25 00:20:41 +01:00
public:
static String default_error_404_body;
static String default_generic_error_body;
void handle_request_main(Request *request);
void handle_error_send_request(Request *request, const int error_code);
2022-01-08 11:47:39 +01:00
bool process_middlewares(Request *request);
bool try_send_wwwroot_file(Request *request);
void send_file(const String &path, Request *request);
2020-11-25 00:20:41 +01:00
static void default_fallback_error_handler(Request *request, int error_code);
static void default_404_error_handler(Request *request, int error_code);
2020-11-25 00:20:41 +01:00
2022-01-08 12:35:44 +01:00
virtual void setup();
virtual void setup_error_handlers();
virtual void setup_middleware();
2020-11-25 00:20:41 +01:00
void default_routing_middleware(Object *instance, Request *request);
void register_request_update(Request *request);
void unregister_request_update(Request *request);
void update();
WebRoot();
virtual ~WebRoot();
2020-11-25 00:20:41 +01:00
public:
Vector<Ref<Middleware> > _middlewares;
std::map<int, std::function<void(Request *, int)> > error_handler_map;
std::function<void(Request *, int)> default_error_handler_func;
2020-11-25 00:20:41 +01:00
protected:
std::mutex _update_registered_requests_mutex;
std::vector<Request *> _update_registered_requests;
2020-11-25 00:20:41 +01:00
};
#endif