mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2025-04-20 01:43:12 +02:00
Renamed the Application class to BryWebApplication.
This commit is contained in:
parent
3931dba988
commit
0c0123889b
@ -1,4 +1,4 @@
|
||||
#include "application.h"
|
||||
#include "bry_web_application.h"
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
@ -12,20 +12,20 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void Application::load_settings() {
|
||||
void BryWebApplication::load_settings() {
|
||||
}
|
||||
|
||||
void Application::setup_routes() {
|
||||
default_error_handler_func = Application::default_fallback_error_handler;
|
||||
void BryWebApplication::setup_routes() {
|
||||
default_error_handler_func = BryWebApplication::default_fallback_error_handler;
|
||||
|
||||
error_handler_map[404] = Application::default_404_error_handler;
|
||||
error_handler_map[404] = BryWebApplication::default_404_error_handler;
|
||||
}
|
||||
|
||||
void Application::setup_middleware() {
|
||||
void BryWebApplication::setup_middleware() {
|
||||
middlewares.push_back(HandlerInstance([this](Object *instance, Request *request){ this->default_routing_middleware(instance, request); }));
|
||||
}
|
||||
|
||||
void Application::default_routing_middleware(Object *instance, Request *request) {
|
||||
void BryWebApplication::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 Application::default_routing_middleware(Object *instance, Request *request)
|
||||
request->next_stage();
|
||||
}
|
||||
|
||||
void Application::default_fallback_error_handler(int error_code, Request *request) {
|
||||
void BryWebApplication::default_fallback_error_handler(int error_code, Request *request) {
|
||||
request->response->setBody(default_generic_error_body);
|
||||
request->send();
|
||||
}
|
||||
|
||||
void Application::default_404_error_handler(int error_code, Request *request) {
|
||||
void BryWebApplication::default_404_error_handler(int error_code, Request *request) {
|
||||
request->response->setBody(default_error_404_body);
|
||||
request->send();
|
||||
}
|
||||
|
||||
void Application::handle_request(Request *request) {
|
||||
void BryWebApplication::handle_request(Request *request) {
|
||||
request->middleware_stack = &middlewares;
|
||||
|
||||
//note that middlewares handle the routing -> Application::default_routing_middleware by default
|
||||
//note that middlewares handle the routing -> BryWebApplication::default_routing_middleware by default
|
||||
request->next_stage();
|
||||
}
|
||||
|
||||
void Application::send_error(int error_code, Request *request) {
|
||||
void BryWebApplication::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 Application::send_error(int error_code, Request *request) {
|
||||
func(error_code, request);
|
||||
}
|
||||
|
||||
void Application::send_file(const std::string &path, Request *request) {
|
||||
void BryWebApplication::send_file(const std::string &path, Request *request) {
|
||||
std::string fp = FileCache::get_singleton()->wwwroot + path;
|
||||
|
||||
request->send_file(fp);
|
||||
}
|
||||
|
||||
void Application::migrate() {
|
||||
void BryWebApplication::migrate() {
|
||||
}
|
||||
|
||||
void Application::register_request_update(Request *request) {
|
||||
void BryWebApplication::register_request_update(Request *request) {
|
||||
std::lock_guard<std::mutex> lock(_update_registered_requests_mutex);
|
||||
|
||||
_update_registered_requests.push_back(request);
|
||||
}
|
||||
void Application::unregister_request_update(Request *request) {
|
||||
void BryWebApplication::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 Application::unregister_request_update(Request *request) {
|
||||
}
|
||||
}
|
||||
|
||||
void Application::update() {
|
||||
void BryWebApplication::update() {
|
||||
for (std::size_t i = 0; i < _update_registered_requests.size(); ++i) {
|
||||
Request *r = _update_registered_requests[i];
|
||||
|
||||
@ -127,14 +127,14 @@ void Application::update() {
|
||||
}
|
||||
}
|
||||
|
||||
Application::Application() {
|
||||
BryWebApplication::BryWebApplication() {
|
||||
}
|
||||
|
||||
Application::~Application() {
|
||||
BryWebApplication::~BryWebApplication() {
|
||||
main_route_map.clear();
|
||||
error_handler_map.clear();
|
||||
middlewares.clear();
|
||||
}
|
||||
|
||||
std::string Application::default_error_404_body = "<html><body>404 :(</body></html>";
|
||||
std::string Application::default_generic_error_body = "<html><body>Internal server error! :(</body></html>";
|
||||
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>";
|
@ -1,5 +1,5 @@
|
||||
#ifndef APPLICATION_H
|
||||
#define APPLICATION_H
|
||||
#ifndef BRY_WEB_APPLICATION_H
|
||||
#define BRY_WEB_APPLICATION_H
|
||||
|
||||
#include "object.h"
|
||||
#include <functional>
|
||||
@ -13,7 +13,7 @@
|
||||
|
||||
class Request;
|
||||
|
||||
class Application {
|
||||
class BryWebApplication {
|
||||
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();
|
||||
|
||||
Application();
|
||||
virtual ~Application();
|
||||
BryWebApplication();
|
||||
virtual ~BryWebApplication();
|
||||
|
||||
public:
|
||||
HandlerInstance index_func;
|
@ -1,6 +1,6 @@
|
||||
#include "http_server.h"
|
||||
|
||||
#include "core/application.h"
|
||||
#include "core/bry_web_application.h"
|
||||
#include "core/request.h"
|
||||
|
||||
#define LOG_VERBOSE 0
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include <brynet/net/wrapper/ServiceBuilder.hpp>
|
||||
|
||||
class Request;
|
||||
class Application;
|
||||
class BryWebApplication;
|
||||
|
||||
class HTTPServer {
|
||||
public:
|
||||
@ -40,7 +40,7 @@ public:
|
||||
virtual ~HTTPServer();
|
||||
|
||||
//move this to a sublcass
|
||||
Application *application;
|
||||
BryWebApplication *application;
|
||||
|
||||
protected:
|
||||
std::map<HttpSession *, Request *> _request_map;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "request.h"
|
||||
|
||||
#include "application.h"
|
||||
#include "bry_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 Application;
|
||||
class BryWebApplication;
|
||||
|
||||
class Request {
|
||||
public:
|
||||
HTTPParser::Ptr http_parser;
|
||||
HttpSession::Ptr session;
|
||||
HttpResponse *response;
|
||||
Application *application;
|
||||
BryWebApplication *application;
|
||||
|
||||
uint32_t current_middleware_index;
|
||||
HandlerInstance handler_instance;
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <tinydir/tinydir.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "core/application.h"
|
||||
#include "core/bry_web_application.h"
|
||||
|
||||
void PagedArticle::index(Request *request) {
|
||||
const std::string r = request->get_current_path_segment();
|
||||
|
Loading…
Reference in New Issue
Block a user