mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-10 00:52:11 +01:00
Renamed BryWebApplication to WebApplication, and moved it and HandlerInstance and Request to a new http folder. Their dependencies with brynet will be removed, they will have subclasses per backend when/if needed.
This commit is contained in:
parent
a34995e1b7
commit
a47cb57da7
@ -6,6 +6,7 @@ env.core_sources = []
|
||||
|
||||
env.add_source_files(env.core_sources, "*.cpp")
|
||||
env.add_source_files(env.core_sources, "./html/*.cpp")
|
||||
env.add_source_files(env.core_sources, "./http/*.cpp")
|
||||
env.add_source_files(env.core_sources, "./bry_http/*.cpp")
|
||||
env.add_source_files(env.core_sources, "./database/*.cpp")
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "http_server.h"
|
||||
|
||||
#include "bry_web_application.h"
|
||||
#include "request.h"
|
||||
#include "core/http/web_application.h"
|
||||
#include "core/http/request.h"
|
||||
|
||||
#define LOG_VERBOSE 0
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include <brynet/net/wrapper/ServiceBuilder.hpp>
|
||||
|
||||
class Request;
|
||||
class BryWebApplication;
|
||||
class WebApplication;
|
||||
|
||||
class HTTPServer {
|
||||
public:
|
||||
@ -40,7 +40,7 @@ public:
|
||||
virtual ~HTTPServer();
|
||||
|
||||
//move this to a sublcass
|
||||
BryWebApplication *application;
|
||||
WebApplication *application;
|
||||
|
||||
protected:
|
||||
std::map<HttpSession *, Request *> _request_map;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "request.h"
|
||||
|
||||
#include "bry_web_application.h"
|
||||
#include "web_application.h"
|
||||
|
||||
void Request::compile_body() {
|
||||
compiled_body.reserve(body.size() + head.size() + 13 + 14 + 15);
|
@ -9,14 +9,14 @@
|
||||
|
||||
#include "handler_instance.h"
|
||||
|
||||
class BryWebApplication;
|
||||
class WebApplication;
|
||||
|
||||
class Request {
|
||||
public:
|
||||
HTTPParser::Ptr http_parser;
|
||||
HttpSession::Ptr session;
|
||||
HttpResponse *response;
|
||||
BryWebApplication *application;
|
||||
WebApplication *application;
|
||||
|
||||
uint32_t current_middleware_index;
|
||||
HandlerInstance handler_instance;
|
@ -1,4 +1,4 @@
|
||||
#include "bry_web_application.h"
|
||||
#include "web_application.h"
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
@ -12,20 +12,20 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void BryWebApplication::load_settings() {
|
||||
void WebApplication::load_settings() {
|
||||
}
|
||||
|
||||
void BryWebApplication::setup_routes() {
|
||||
default_error_handler_func = BryWebApplication::default_fallback_error_handler;
|
||||
void WebApplication::setup_routes() {
|
||||
default_error_handler_func = WebApplication::default_fallback_error_handler;
|
||||
|
||||
error_handler_map[404] = BryWebApplication::default_404_error_handler;
|
||||
error_handler_map[404] = WebApplication::default_404_error_handler;
|
||||
}
|
||||
|
||||
void BryWebApplication::setup_middleware() {
|
||||
void WebApplication::setup_middleware() {
|
||||
middlewares.push_back(HandlerInstance([this](Object *instance, Request *request){ this->default_routing_middleware(instance, request); }));
|
||||
}
|
||||
|
||||
void BryWebApplication::default_routing_middleware(Object *instance, Request *request) {
|
||||
void WebApplication::default_routing_middleware(Object *instance, Request *request) {
|
||||
std::string path = request->http_parser->getPath();
|
||||
|
||||
if (FileCache::get_singleton()->wwwroot_has_file(path)) {
|
||||
@ -60,24 +60,24 @@ void BryWebApplication::default_routing_middleware(Object *instance, Request *re
|
||||
request->next_stage();
|
||||
}
|
||||
|
||||
void BryWebApplication::default_fallback_error_handler(int error_code, Request *request) {
|
||||
void WebApplication::default_fallback_error_handler(int error_code, Request *request) {
|
||||
request->response->setBody(default_generic_error_body);
|
||||
request->send();
|
||||
}
|
||||
|
||||
void BryWebApplication::default_404_error_handler(int error_code, Request *request) {
|
||||
void WebApplication::default_404_error_handler(int error_code, Request *request) {
|
||||
request->response->setBody(default_error_404_body);
|
||||
request->send();
|
||||
}
|
||||
|
||||
void BryWebApplication::handle_request(Request *request) {
|
||||
void WebApplication::handle_request(Request *request) {
|
||||
request->middleware_stack = &middlewares;
|
||||
|
||||
//note that middlewares handle the routing -> BryWebApplication::default_routing_middleware by default
|
||||
//note that middlewares handle the routing -> WebApplication::default_routing_middleware by default
|
||||
request->next_stage();
|
||||
}
|
||||
|
||||
void BryWebApplication::send_error(int error_code, Request *request) {
|
||||
void WebApplication::send_error(int error_code, Request *request) {
|
||||
std::function<void(int, Request *)> func = error_handler_map[error_code];
|
||||
|
||||
if (!func) {
|
||||
@ -88,21 +88,21 @@ void BryWebApplication::send_error(int error_code, Request *request) {
|
||||
func(error_code, request);
|
||||
}
|
||||
|
||||
void BryWebApplication::send_file(const std::string &path, Request *request) {
|
||||
void WebApplication::send_file(const std::string &path, Request *request) {
|
||||
std::string fp = FileCache::get_singleton()->wwwroot + path;
|
||||
|
||||
request->send_file(fp);
|
||||
}
|
||||
|
||||
void BryWebApplication::migrate() {
|
||||
void WebApplication::migrate() {
|
||||
}
|
||||
|
||||
void BryWebApplication::register_request_update(Request *request) {
|
||||
void WebApplication::register_request_update(Request *request) {
|
||||
std::lock_guard<std::mutex> lock(_update_registered_requests_mutex);
|
||||
|
||||
_update_registered_requests.push_back(request);
|
||||
}
|
||||
void BryWebApplication::unregister_request_update(Request *request) {
|
||||
void WebApplication::unregister_request_update(Request *request) {
|
||||
std::lock_guard<std::mutex> lock(_update_registered_requests_mutex);
|
||||
|
||||
std::size_t s = _update_registered_requests.size();
|
||||
@ -119,7 +119,7 @@ void BryWebApplication::unregister_request_update(Request *request) {
|
||||
}
|
||||
}
|
||||
|
||||
void BryWebApplication::update() {
|
||||
void WebApplication::update() {
|
||||
for (std::size_t i = 0; i < _update_registered_requests.size(); ++i) {
|
||||
Request *r = _update_registered_requests[i];
|
||||
|
||||
@ -127,14 +127,14 @@ void BryWebApplication::update() {
|
||||
}
|
||||
}
|
||||
|
||||
BryWebApplication::BryWebApplication() {
|
||||
WebApplication::WebApplication() {
|
||||
}
|
||||
|
||||
BryWebApplication::~BryWebApplication() {
|
||||
WebApplication::~WebApplication() {
|
||||
main_route_map.clear();
|
||||
error_handler_map.clear();
|
||||
middlewares.clear();
|
||||
}
|
||||
|
||||
std::string BryWebApplication::default_error_404_body = "<html><body>404 :(</body></html>";
|
||||
std::string BryWebApplication::default_generic_error_body = "<html><body>Internal server error! :(</body></html>";
|
||||
std::string WebApplication::default_error_404_body = "<html><body>404 :(</body></html>";
|
||||
std::string WebApplication::default_generic_error_body = "<html><body>Internal server error! :(</body></html>";
|
@ -1,5 +1,5 @@
|
||||
#ifndef BRY_WEB_APPLICATION_H
|
||||
#define BRY_WEB_APPLICATION_H
|
||||
#ifndef WEB_APPLICATION_H
|
||||
#define WEB_APPLICATION_H
|
||||
|
||||
#include "core/object.h"
|
||||
#include <functional>
|
||||
@ -13,7 +13,7 @@
|
||||
|
||||
class Request;
|
||||
|
||||
class BryWebApplication {
|
||||
class WebApplication {
|
||||
public:
|
||||
static std::string default_error_404_body;
|
||||
static std::string default_generic_error_body;
|
||||
@ -37,8 +37,8 @@ public:
|
||||
void unregister_request_update(Request *request);
|
||||
void update();
|
||||
|
||||
BryWebApplication();
|
||||
virtual ~BryWebApplication();
|
||||
WebApplication();
|
||||
virtual ~WebApplication();
|
||||
|
||||
public:
|
||||
HandlerInstance index_func;
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include "core/object.h"
|
||||
|
||||
#include "core/bry_http/request.h"
|
||||
#include "core/http/request.h"
|
||||
|
||||
|
||||
class ListPage : public Object {
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include "core/object.h"
|
||||
|
||||
#include "core/bry_http/request.h"
|
||||
#include "core/http/request.h"
|
||||
|
||||
|
||||
class MessagePage : public Object {
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <tinydir/tinydir.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "core/bry_http/bry_web_application.h"
|
||||
#include "core/http/web_application.h"
|
||||
|
||||
void PagedArticle::index(Request *request) {
|
||||
const std::string r = request->get_current_path_segment();
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "core/file_cache.h"
|
||||
#include "core/object.h"
|
||||
|
||||
#include "core/bry_http/request.h"
|
||||
#include "core/http/request.h"
|
||||
|
||||
struct Article {
|
||||
std::string url;
|
||||
|
Loading…
Reference in New Issue
Block a user