rcpp_framework/core/http/web_root.h

74 lines
1.9 KiB
C
Raw Normal View History

#ifndef WEB_ROOT_H
#define WEB_ROOT_H
2020-11-25 00:20:41 +01:00
#include "web_router_node.h"
2020-11-25 00:20:41 +01:00
#include <functional>
#include <map>
#include <string>
#include <vector>
#include "mutex"
#include "handler_instance.h"
2020-11-25 00:20:41 +01:00
class Request;
class WebServer;
2020-11-25 00:20:41 +01:00
2022-01-08 10:50:07 +01:00
//Middleware turn into a class (reference)
//add them to a folder
//method should return bool -> true to continue, false if done
//Error handlers
//Add to WebNode api -> send_error(code) v handle_error_send_request(request, int error, variant additional data ?);
//have generic one implemented by default
//Webroot overrides -> uses same logic as now
//notification -> variant additional data?
//FileCache -> set up, for this webroot, don't use singleton
class WebRoot : public WebRouterNode {
RCPP_OBJECT(WebRoot, WebRouterNode);
2021-11-21 14:40:47 +01:00
2020-11-25 00:20:41 +01:00
public:
static std::string default_error_404_body;
static std::string default_generic_error_body;
void handle_request_main(Request *request);
void send_error(int error_code, Request *request);
void send_file(const std::string &path, Request *request);
2020-11-25 00:20:41 +01:00
static void default_fallback_error_handler(int error_code, Request *request);
static void default_404_error_handler(int error_code, Request *request);
2020-11-25 00:20:41 +01:00
2020-12-08 16:22:18 +01:00
virtual void load_settings();
2020-11-25 00:20:41 +01:00
virtual void setup_routes();
virtual void setup_middleware();
2020-11-25 00:20:41 +01:00
void default_routing_middleware(Object *instance, Request *request);
virtual void migrate();
void register_request_update(Request *request);
void unregister_request_update(Request *request);
void update();
WebServer *get_server();
WebRoot();
virtual ~WebRoot();
2020-11-25 00:20:41 +01:00
public:
HandlerInstance index_func;
std::map<std::string, HandlerInstance> main_route_map;
std::vector<HandlerInstance> middlewares;
2020-11-25 00:20:41 +01:00
std::map<int, std::function<void(int, Request *)> > error_handler_map;
std::function<void(int, Request *)> 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