mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2025-05-06 17:51:36 +02:00
Added lots of simple getter/setter methods to the new web app from drogon.
This commit is contained in:
parent
c4c9d34e35
commit
383fc2a259
@ -60,12 +60,16 @@ public:
|
|||||||
size_t getThreadNum() const override {
|
size_t getThreadNum() const override {
|
||||||
return threadNum_;
|
return threadNum_;
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpAppFramework &setSSLConfigCommands(
|
HttpAppFramework &setSSLConfigCommands(
|
||||||
const std::vector<std::pair<std::string, std::string> > &sslConfCmds)
|
const std::vector<std::pair<std::string, std::string> > &sslConfCmds)
|
||||||
override;
|
override;
|
||||||
|
|
||||||
HttpAppFramework &setSSLFiles(const std::string &certPath,
|
HttpAppFramework &setSSLFiles(const std::string &certPath,
|
||||||
const std::string &keyPath) override;
|
const std::string &keyPath) override;
|
||||||
|
|
||||||
void run() override;
|
void run() override;
|
||||||
|
|
||||||
HttpAppFramework ®isterWebSocketController(
|
HttpAppFramework ®isterWebSocketController(
|
||||||
const std::string &pathName,
|
const std::string &pathName,
|
||||||
const std::string &ctrlName,
|
const std::string &ctrlName,
|
||||||
|
@ -47,6 +47,7 @@ void DRequest::send() {
|
|||||||
// return;
|
// return;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
/*
|
||||||
if (http_parser->isKeepAlive()) {
|
if (http_parser->isKeepAlive()) {
|
||||||
response->addHeadValue("Connection", "Keep-Alive");
|
response->addHeadValue("Connection", "Keep-Alive");
|
||||||
|
|
||||||
@ -62,7 +63,7 @@ void DRequest::send() {
|
|||||||
|
|
||||||
session->send(result.c_str(), result.size(), [lsession]() { lsession->postShutdown(); });
|
session->send(result.c_str(), result.size(), [lsession]() { lsession->postShutdown(); });
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
DRequestPool::return_request(this);
|
DRequestPool::return_request(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +72,7 @@ void DRequest::send_file(const std::string &p_file_path) {
|
|||||||
// DRequestPool::return_request(this);
|
// DRequestPool::return_request(this);
|
||||||
// return;
|
// return;
|
||||||
//}
|
//}
|
||||||
|
/*
|
||||||
file_path = p_file_path;
|
file_path = p_file_path;
|
||||||
|
|
||||||
FILE *f = fopen(file_path.c_str(), "rb");
|
FILE *f = fopen(file_path.c_str(), "rb");
|
||||||
@ -92,6 +93,7 @@ void DRequest::send_file(const std::string &p_file_path) {
|
|||||||
application->register_request_update(this);
|
application->register_request_update(this);
|
||||||
|
|
||||||
session->send(result.c_str(), result.size(), [this]() { this->_file_chunk_sent(); });
|
session->send(result.c_str(), result.size(), [this]() { this->_file_chunk_sent(); });
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void DRequest::send_error(int error_code) {
|
void DRequest::send_error(int error_code) {
|
||||||
@ -100,8 +102,6 @@ void DRequest::send_error(int error_code) {
|
|||||||
|
|
||||||
void DRequest::reset() {
|
void DRequest::reset() {
|
||||||
application = nullptr;
|
application = nullptr;
|
||||||
http_parser = nullptr;
|
|
||||||
session = nullptr;
|
|
||||||
current_middleware_index = 0;
|
current_middleware_index = 0;
|
||||||
middleware_stack = nullptr;
|
middleware_stack = nullptr;
|
||||||
_path_stack.clear();
|
_path_stack.clear();
|
||||||
@ -118,10 +118,11 @@ void DRequest::reset() {
|
|||||||
if (response)
|
if (response)
|
||||||
delete response;
|
delete response;
|
||||||
|
|
||||||
response = new HttpResponse();
|
//response = new HttpResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DRequest::setup_url_stack() {
|
void DRequest::setup_url_stack() {
|
||||||
|
/*
|
||||||
std::string path = http_parser->getPath();
|
std::string path = http_parser->getPath();
|
||||||
|
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
@ -137,6 +138,7 @@ void DRequest::setup_url_stack() {
|
|||||||
|
|
||||||
if (path.size() != 0)
|
if (path.size() != 0)
|
||||||
_path_stack.push_back(path);
|
_path_stack.push_back(path);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DRequest::get_path() const {
|
std::string DRequest::get_path() const {
|
||||||
@ -151,7 +153,9 @@ std::string DRequest::get_path() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const std::string &DRequest::get_path_full() const {
|
const std::string &DRequest::get_path_full() const {
|
||||||
return http_parser->getPath();
|
static std::string a = "";
|
||||||
|
return a;
|
||||||
|
//return http_parser->getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &DRequest::get_path_segment(const uint32_t i) const {
|
const std::string &DRequest::get_path_segment(const uint32_t i) const {
|
||||||
@ -215,6 +219,7 @@ DRequest::~DRequest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DRequest::_progress_send_file() {
|
void DRequest::_progress_send_file() {
|
||||||
|
/*
|
||||||
if (connection_closed) {
|
if (connection_closed) {
|
||||||
DRequestPool::return_request(this);
|
DRequestPool::return_request(this);
|
||||||
return;
|
return;
|
||||||
@ -259,6 +264,7 @@ void DRequest::_progress_send_file() {
|
|||||||
current_file_progress = nfp;
|
current_file_progress = nfp;
|
||||||
|
|
||||||
session->send(body.c_str(), body.size(), [this]() { this->_file_chunk_sent(); });
|
session->send(body.c_str(), body.size(), [this]() { this->_file_chunk_sent(); });
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void DRequest::_file_chunk_sent() {
|
void DRequest::_file_chunk_sent() {
|
||||||
|
@ -4,17 +4,16 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <brynet/net/http/HttpFormat.hpp>
|
#include "http/HttpResponse.h"
|
||||||
#include <brynet/net/http/HttpService.hpp>
|
|
||||||
|
|
||||||
#include "handler_instance.h"
|
#include "handler_instance.h"
|
||||||
|
|
||||||
|
using namespace drogon;
|
||||||
|
|
||||||
class DWebApplication;
|
class DWebApplication;
|
||||||
|
|
||||||
class DRequest {
|
class DRequest {
|
||||||
public:
|
public:
|
||||||
HTTPParser::Ptr http_parser;
|
|
||||||
HttpSession::Ptr session;
|
|
||||||
HttpResponse *response;
|
HttpResponse *response;
|
||||||
DWebApplication *application;
|
DWebApplication *application;
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ void DWebApplication::setup_middleware() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DWebApplication::default_routing_middleware(Object *instance, DRequest *request) {
|
void DWebApplication::default_routing_middleware(Object *instance, DRequest *request) {
|
||||||
|
/*
|
||||||
std::string path = request->http_parser->getPath();
|
std::string path = request->http_parser->getPath();
|
||||||
|
|
||||||
if (FileCache::get_singleton()->wwwroot_has_file(path)) {
|
if (FileCache::get_singleton()->wwwroot_has_file(path)) {
|
||||||
@ -58,6 +59,7 @@ void DWebApplication::default_routing_middleware(Object *instance, DRequest *req
|
|||||||
|
|
||||||
request->handler_instance = handler_data;
|
request->handler_instance = handler_data;
|
||||||
request->next_stage();
|
request->next_stage();
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void DWebApplication::default_fallback_error_handler(int error_code, DRequest *request) {
|
void DWebApplication::default_fallback_error_handler(int error_code, DRequest *request) {
|
||||||
|
@ -11,6 +11,18 @@
|
|||||||
|
|
||||||
#include "handler_instance.h"
|
#include "handler_instance.h"
|
||||||
|
|
||||||
|
#include <trantor/utils/Logger.h>
|
||||||
|
#include <trantor/net/InetAddress.h>
|
||||||
|
|
||||||
|
#include "http/HttpRequestImpl.h"
|
||||||
|
#include "http/HttpResponse.h"
|
||||||
|
|
||||||
|
#include "./drogon/lib/src/impl_forwards.h"
|
||||||
|
|
||||||
|
#include "http/SessionManager.h"
|
||||||
|
|
||||||
|
using namespace drogon;
|
||||||
|
|
||||||
class DRequest;
|
class DRequest;
|
||||||
|
|
||||||
class DWebApplication {
|
class DWebApplication {
|
||||||
@ -37,6 +49,117 @@ public:
|
|||||||
void unregister_request_update(DRequest *request);
|
void unregister_request_update(DRequest *request);
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
void addListener(const std::string &ip, uint16_t port, bool useSSL, const std::string &certFile, const std::string &keyFile, bool useOldTLS, const std::vector<std::pair<std::string, std::string> > &sslConfCmds);
|
||||||
|
|
||||||
|
void setThreadNum(size_t threadNum);
|
||||||
|
size_t getThreadNum() const;
|
||||||
|
|
||||||
|
void setSSLConfigCommands(const std::vector<std::pair<std::string, std::string> > &sslConfCmds);
|
||||||
|
void setSSLFiles(const std::string &certPath, const std::string &keyPath);
|
||||||
|
|
||||||
|
void run();
|
||||||
|
void stop();
|
||||||
|
|
||||||
|
void enableSession(const size_t timeout);
|
||||||
|
void disableSession();
|
||||||
|
|
||||||
|
//todo think about it
|
||||||
|
const std::string &getDocumentRoot() const;
|
||||||
|
void setDocumentRoot(const std::string &rootPath);
|
||||||
|
|
||||||
|
void setStaticFileHeaders(const std::vector<std::pair<std::string, std::string> > &headers);
|
||||||
|
|
||||||
|
const std::string &getUploadPath() const;
|
||||||
|
|
||||||
|
const std::shared_ptr<trantor::Resolver> &getResolver() const;
|
||||||
|
|
||||||
|
void setUploadPath(const std::string &uploadPath);
|
||||||
|
void setFileTypes(const std::vector<std::string> &types);
|
||||||
|
|
||||||
|
void setMaxConnectionNum(size_t maxConnections);
|
||||||
|
void setMaxConnectionNumPerIP(size_t maxConnectionsPerIP);
|
||||||
|
|
||||||
|
void setLogPath(const std::string &logPath, const std::string &logfileBaseName, size_t logfileSize);
|
||||||
|
void setLogLevel(trantor::Logger::LogLevel level);
|
||||||
|
void enableSendfile(bool sendFile);
|
||||||
|
void enableGzip(bool useGzip);
|
||||||
|
bool isGzipEnabled() const;
|
||||||
|
void enableBrotli(bool useBrotli);
|
||||||
|
bool isBrotliEnabled() const;
|
||||||
|
|
||||||
|
void setStaticFilesCacheTime(int cacheTime);
|
||||||
|
int staticFilesCacheTime() const;
|
||||||
|
|
||||||
|
void setIdleConnectionTimeout(size_t timeout);
|
||||||
|
void setKeepaliveRequestsNumber(const size_t number);
|
||||||
|
void setPipeliningRequestsNumber(const size_t number);
|
||||||
|
|
||||||
|
void setGzipStatic(bool useGzipStatic);
|
||||||
|
void setBrStatic(bool useGzipStatic);
|
||||||
|
|
||||||
|
void setClientMaxBodySize(size_t maxSize);
|
||||||
|
void setClientMaxMemoryBodySize(size_t maxSize);
|
||||||
|
void setClientMaxWebSocketMessageSize(size_t maxSize);
|
||||||
|
|
||||||
|
void setHomePage(const std::string &homePageFile);
|
||||||
|
const std::string &getHomePage() const;
|
||||||
|
|
||||||
|
void setImplicitPageEnable(bool useImplicitPage);
|
||||||
|
bool isImplicitPageEnabled() const;
|
||||||
|
void setImplicitPage(const std::string &implicitPageFile);
|
||||||
|
|
||||||
|
const std::string &getImplicitPage() const;
|
||||||
|
size_t getClientMaxBodySize() const;
|
||||||
|
size_t getClientMaxMemoryBodySize() const;
|
||||||
|
size_t getClientMaxWebSocketMessageSize() const;
|
||||||
|
|
||||||
|
size_t keepaliveRequestsNumber() const;
|
||||||
|
size_t pipeliningRequestsNumber() const;
|
||||||
|
|
||||||
|
bool isRunning();
|
||||||
|
|
||||||
|
void setUnicodeEscapingInJson(bool enable);
|
||||||
|
|
||||||
|
bool isUnicodeEscapingUsedInJson() const;
|
||||||
|
void setFloatPrecisionInJson(unsigned int precision, const std::string &precisionType);
|
||||||
|
|
||||||
|
const std::pair<unsigned int, std::string> &getFloatPrecisionInJson() const;
|
||||||
|
|
||||||
|
trantor::EventLoop *getLoop() const;
|
||||||
|
trantor::EventLoop *getIOLoop(size_t id) const;
|
||||||
|
|
||||||
|
void setServerHeaderField(const std::string &server);
|
||||||
|
|
||||||
|
void enableServerHeader(bool flag);
|
||||||
|
void enableDateHeader(bool flag);
|
||||||
|
|
||||||
|
bool sendServerHeader() const;
|
||||||
|
bool sendDateHeader() const;
|
||||||
|
|
||||||
|
const std::string &getServerHeaderString() const;
|
||||||
|
|
||||||
|
std::vector<trantor::InetAddress> getListeners() const;
|
||||||
|
|
||||||
|
bool useSendfile() const;
|
||||||
|
|
||||||
|
bool supportSSL() const;
|
||||||
|
|
||||||
|
size_t getCurrentThreadIndex() const;
|
||||||
|
|
||||||
|
void enableReusePort(bool enable);
|
||||||
|
|
||||||
|
bool reusePort() const;
|
||||||
|
|
||||||
|
void onAsyncRequest(const HttpRequestImplPtr &req, std::function<void(const HttpResponsePtr &)> &&callback);
|
||||||
|
void onNewWebsockRequest(const HttpRequestImplPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, const WebSocketConnectionImplPtr &wsConnPtr);
|
||||||
|
void onConnection(const trantor::TcpConnectionPtr &conn);
|
||||||
|
|
||||||
|
void findSessionForRequest(const HttpRequestImplPtr &req);
|
||||||
|
|
||||||
|
//to request
|
||||||
|
//void forward(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,const std::string &hostString,double timeout);
|
||||||
|
//void forward(const HttpRequestImplPtr &req,std::function<void(const HttpResponsePtr &)> &&callback,const std::string &hostString,double timeout = 0);
|
||||||
|
|
||||||
DWebApplication();
|
DWebApplication();
|
||||||
virtual ~DWebApplication();
|
virtual ~DWebApplication();
|
||||||
|
|
||||||
@ -51,6 +174,51 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
std::mutex _update_registered_requests_mutex;
|
std::mutex _update_registered_requests_mutex;
|
||||||
std::vector<DRequest *> _update_registered_requests;
|
std::vector<DRequest *> _update_registered_requests;
|
||||||
|
|
||||||
|
// We use a uuid string as session id;
|
||||||
|
// set sessionTimeout_=0 to make location session valid forever based on
|
||||||
|
// cookies;
|
||||||
|
size_t _session_timeout{ 0 };
|
||||||
|
size_t _idle_connection_timeout{ 60 };
|
||||||
|
bool _use_session{ false };
|
||||||
|
std::string _server_header { "server: rcpp_framework\r\n" };
|
||||||
|
|
||||||
|
std::string _root_path { "./" };
|
||||||
|
std::string _upload_path;
|
||||||
|
std::atomic_bool _running { false };
|
||||||
|
|
||||||
|
size_t _thread_num{ 1 };
|
||||||
|
|
||||||
|
std::vector<std::pair<std::string, std::string> > _ssl_conf_cmds;
|
||||||
|
std::string _ssl_cert_path;
|
||||||
|
std::string _ssl_key_path;
|
||||||
|
|
||||||
|
size_t _max_connection_num_per_ip{ 0 };
|
||||||
|
std::unordered_map<std::string, size_t> _connections_num_map;
|
||||||
|
|
||||||
|
int64_t _max_connection_num{ 100000 };
|
||||||
|
std::atomic<int64_t> _connection_num{ 0 };
|
||||||
|
|
||||||
|
std::string _log_path;
|
||||||
|
std::string _logfile_base_name;
|
||||||
|
size_t _logfile_size{ 100000000 };
|
||||||
|
size_t _keepalive_requests_number{ 0 };
|
||||||
|
size_t _pipelining_requests_number{ 0 };
|
||||||
|
bool _use_sendfile{ true };
|
||||||
|
bool _use_gzip{ true };
|
||||||
|
bool _use_brotli{ false };
|
||||||
|
bool _using_unicode_escaping{ true };
|
||||||
|
|
||||||
|
size_t _client_max_body_size{ 1024 * 1024 };
|
||||||
|
size_t _client_max_memory_body_size{ 64 * 1024 };
|
||||||
|
size_t _client_max_web_socket_message_size{ 128 * 1024 };
|
||||||
|
std::string _home_page_file{ "index.html" };
|
||||||
|
|
||||||
|
std::unique_ptr<SessionManager> _sessionManagerPtr;
|
||||||
|
|
||||||
|
bool _enable_server_header{ true };
|
||||||
|
bool _enable_date_header{ true };
|
||||||
|
bool _reuse_port{ false };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue
Block a user