diff --git a/core/SCsub b/core/SCsub index ea8cfdb..75aa13b 100644 --- a/core/SCsub +++ b/core/SCsub @@ -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") diff --git a/core/bry_http/http_server.cpp b/core/bry_http/http_server.cpp index 4e3a32c..f3e598d 100644 --- a/core/bry_http/http_server.cpp +++ b/core/bry_http/http_server.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 diff --git a/core/bry_http/http_server.h b/core/bry_http/http_server.h index 5dd39a4..45972a2 100644 --- a/core/bry_http/http_server.h +++ b/core/bry_http/http_server.h @@ -15,7 +15,7 @@ #include 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 _request_map; diff --git a/core/bry_http/handler_instance.cpp b/core/http/handler_instance.cpp similarity index 100% rename from core/bry_http/handler_instance.cpp rename to core/http/handler_instance.cpp diff --git a/core/bry_http/handler_instance.h b/core/http/handler_instance.h similarity index 100% rename from core/bry_http/handler_instance.h rename to core/http/handler_instance.h diff --git a/core/bry_http/request.cpp b/core/http/request.cpp similarity index 99% rename from core/bry_http/request.cpp rename to core/http/request.cpp index 80368e2..7b62d31 100644 --- a/core/bry_http/request.cpp +++ b/core/http/request.cpp @@ -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); diff --git a/core/bry_http/request.h b/core/http/request.h similarity index 96% rename from core/bry_http/request.h rename to core/http/request.h index 99c00cb..98413f0 100644 --- a/core/bry_http/request.h +++ b/core/http/request.h @@ -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; diff --git a/core/bry_http/bry_web_application.cpp b/core/http/web_application.cpp similarity index 61% rename from core/bry_http/bry_web_application.cpp rename to core/http/web_application.cpp index 35a996c..30036e5 100644 --- a/core/bry_http/bry_web_application.cpp +++ b/core/http/web_application.cpp @@ -1,4 +1,4 @@ -#include "bry_web_application.h" +#include "web_application.h" #include #include @@ -12,20 +12,20 @@ #include #include -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 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 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 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 = "404 :("; -std::string BryWebApplication::default_generic_error_body = "Internal server error! :("; +std::string WebApplication::default_error_404_body = "404 :("; +std::string WebApplication::default_generic_error_body = "Internal server error! :("; diff --git a/core/bry_http/bry_web_application.h b/core/http/web_application.h similarity index 90% rename from core/bry_http/bry_web_application.h rename to core/http/web_application.h index 01499f4..713d661 100644 --- a/core/bry_http/bry_web_application.h +++ b/core/http/web_application.h @@ -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 @@ -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; diff --git a/modules/list_page/list_page.h b/modules/list_page/list_page.h index 38a31de..6d9b7a6 100644 --- a/modules/list_page/list_page.h +++ b/modules/list_page/list_page.h @@ -6,7 +6,7 @@ #include "core/object.h" -#include "core/bry_http/request.h" +#include "core/http/request.h" class ListPage : public Object { diff --git a/modules/message_page/message_page.h b/modules/message_page/message_page.h index 523fb08..4d884af 100644 --- a/modules/message_page/message_page.h +++ b/modules/message_page/message_page.h @@ -6,7 +6,7 @@ #include "core/object.h" -#include "core/bry_http/request.h" +#include "core/http/request.h" class MessagePage : public Object { diff --git a/modules/paged_article/paged_article.cpp b/modules/paged_article/paged_article.cpp index 498f94e..cc60fb1 100644 --- a/modules/paged_article/paged_article.cpp +++ b/modules/paged_article/paged_article.cpp @@ -8,7 +8,7 @@ #include #include -#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(); diff --git a/modules/paged_article/paged_article.h b/modules/paged_article/paged_article.h index ea3b676..cdfef23 100644 --- a/modules/paged_article/paged_article.h +++ b/modules/paged_article/paged_article.h @@ -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;