16#ifdef __cpp_impl_coroutine
19#include <drogon/exports.h>
20#include <drogon/utils/HttpConstraint.h>
27#include <drogon/drogon_callbacks.h>
34#include <drogon/nosql/RedisClient.h>
36#include <trantor/net/Resolver.h>
37#include <trantor/net/EventLoop.h>
38#include <trantor/utils/NonCopyable.h>
46#if defined(__APPLE__) && defined(__MACH__) && \
47 (defined(__ENVIRONMENT_IPHONE_OS__) || \
48 defined(__IPHONE_OS_VERSION_MIN_REQUIRED))
50#define TARGET_OS_IOS 1
53#define TARGET_OS_IOS 0
61 " __| |_ __ ___ __ _ ___ _ __ \n"
62 " / _` | '__/ _ \\ / _` |/ _ \\| '_ \\ \n"
63 "| (_| | | | (_) | (_| | (_) | | | |\n"
64 " \\__,_|_| \\___/ \\__, |\\___/|_| |_|\n"
67DROGON_EXPORT std::string getVersion();
68DROGON_EXPORT std::string getGitCommit();
73using ExceptionHandler =
74 std::function<void(
const std::exception &,
75 const HttpRequestPtr &,
76 std::function<
void(
const HttpResponsePtr &)> &&)>;
78 std::function<void(
const HttpRequestPtr &,
79 std::function<
void(
const HttpResponsePtr &)> &&)>;
80using HttpHandlerInfo = std::tuple<std::string, HttpMethod, std::string>;
82#ifdef __cpp_impl_coroutine
87struct [[nodiscard]] ForwardAwaiter
88 :
public CallbackAwaiter<drogon::HttpResponsePtr>
91 ForwardAwaiter(drogon::HttpRequestPtr &&req,
94 HttpAppFramework &app)
95 : req_(std::move(req)),
96 host_(std::move(host)),
102 void await_suspend(std::coroutine_handle<> handle)
noexcept;
105 drogon::HttpRequestPtr req_;
108 HttpAppFramework &app_;
158 virtual trantor::EventLoop *
getLoop()
const = 0;
168 virtual trantor::EventLoop *
getIOLoop(
size_t id)
const = 0;
179 bool set404 =
true) = 0;
187 std::function<HttpResponsePtr(HttpStatusCode,
188 const HttpRequestPtr &req)>
189 &&resp_generator) = 0;
192 std::function<HttpResponsePtr(HttpStatusCode)> &&resp_generator)
195 [cb = std::move(resp_generator)](HttpStatusCode code,
196 const HttpRequestPtr &) {
207 virtual const std::function<HttpResponsePtr(HttpStatusCode,
208 const HttpRequestPtr &req)> &
218 template <
typename T>
221 static_assert(IsPlugin<T>::value,
222 "The Template parameter must be a subclass of "
225 static auto pluginPtr =
226 dynamic_cast<T *
>(
getPlugin(T::classTypeName()));
237 template <
typename T>
240 static_assert(IsPlugin<T>::value,
241 "The Template parameter must be a subclass of "
244 static auto pluginPtr =
269 const std::string &name) = 0;
278 const std::function<
void()> &advice) = 0;
289 const std::function<
bool(
const trantor::InetAddress &,
290 const trantor::InetAddress &)> &advice) = 0;
304 const std::function<
void(
const HttpResponsePtr &)> &advice) = 0;
357 const std::function<HttpResponsePtr(
const HttpRequestPtr &)>
368 const std::function<
void(
const HttpRequestPtr &,
370 AdviceChainCallback &&)> &advice) = 0;
380 const std::function<
void(
const HttpRequestPtr &)> &advice) = 0;
390 const std::function<
void(
const HttpRequestPtr &,
392 AdviceChainCallback &&)> &advice) = 0;
402 const std::function<
void(
const HttpRequestPtr &)> &advice) = 0;
411 const std::function<
void(
const HttpRequestPtr &,
413 AdviceChainCallback &&)> &advice) = 0;
423 const std::function<
void(
const HttpRequestPtr &)> &advice) = 0;
431 const std::function<
void(
const HttpRequestPtr &,
432 const HttpResponsePtr &)> &advice) = 0;
440 const std::function<
void(
const HttpRequestPtr &,
441 const HttpResponsePtr &)> &advice) = 0;
461 const std::string &fileName)
noexcept(
false) = 0;
502 const std::string &pathName,
503 const std::string &ctrlName,
504 const std::vector<internal::HttpConstraint> &constraints = {}) = 0;
534 template <
typename FUNCTION>
536 const std::string &pathPattern,
538 const std::vector<internal::HttpConstraint> &constraints = {},
539 const std::string &handlerName =
"")
541 LOG_TRACE <<
"pathPattern:" << pathPattern;
542 auto binder = std::make_shared<internal::HttpBinder<FUNCTION>>(
543 std::forward<FUNCTION>(function));
545 getLoop()->queueInLoop([binder]() { binder->createHandlerInstance(); });
547 std::vector<HttpMethod> validMethods;
548 std::vector<std::string> middlewares;
549 for (
auto const &constraint : constraints)
551 if (constraint.type() == internal::ConstraintType::HttpMiddleware)
553 middlewares.push_back(constraint.getMiddlewareName());
555 else if (constraint.type() == internal::ConstraintType::HttpMethod)
557 validMethods.push_back(constraint.getHttpMethod());
561 LOG_ERROR <<
"Invalid controller constraint type";
565 registerHttpController(
566 pathPattern, binder, validMethods, middlewares, handlerName);
585 template <
typename FUNCTION>
587 const std::string ®Exp,
589 const std::vector<internal::HttpConstraint> &constraints = {},
590 const std::string &handlerName =
"")
592 LOG_TRACE <<
"regex:" << regExp;
593 internal::HttpBinderBasePtr binder;
595 binder = std::make_shared<internal::HttpBinder<FUNCTION>>(
596 std::forward<FUNCTION>(function));
598 std::vector<HttpMethod> validMethods;
599 std::vector<std::string> middlewares;
600 for (
auto const &constraint : constraints)
602 if (constraint.type() == internal::ConstraintType::HttpMiddleware)
604 middlewares.push_back(constraint.getMiddlewareName());
606 else if (constraint.type() == internal::ConstraintType::HttpMethod)
608 validMethods.push_back(constraint.getHttpMethod());
612 LOG_ERROR <<
"Invalid controller constraint type";
616 registerHttpControllerViaRegex(
617 regExp, binder, validMethods, middlewares, handlerName);
627 const std::string &pathName,
628 const std::string &ctrlName,
629 const std::vector<internal::HttpConstraint> &constraints = {}) = 0;
638 const std::string ®Exp,
639 const std::string &ctrlName,
640 const std::vector<internal::HttpConstraint> &constraints =
641 std::vector<internal::HttpConstraint>{}) = 0;
671 template <
typename T>
674 static_assert((std::is_base_of<HttpControllerBase, T>::value ||
675 std::is_base_of<HttpSimpleControllerBase, T>::value ||
676 std::is_base_of<WebSocketControllerBase, T>::value),
677 "Error! Only controller objects can be registered here");
678 static_assert(!T::isAutoCreation,
679 "Controllers created and initialized "
680 "automatically by drogon cannot be "
683 T::initPathRouting();
691 template <
typename T>
694 static_assert(std::is_base_of<HttpFilterBase, T>::value,
695 "Error! Only filter objects can be registered here");
696 static_assert(!T::isAutoCreation,
697 "Filters created and initialized "
698 "automatically by drogon cannot be "
708 template <
typename T>
710 const std::shared_ptr<T> &middlewarePtr)
712 static_assert(std::is_base_of<HttpMiddlewareBase, T>::value,
713 "Error! Only middleware objects can be registered here");
714 static_assert(!T::isAutoCreation,
715 "Middleware created and initialized "
716 "automatically by drogon cannot be "
761 const HttpRequestPtr &req,
762 std::function<
void(
const HttpResponsePtr &)> &&callback,
763 const std::string &hostString =
"",
764 double timeout = 0) = 0;
765#ifdef __cpp_impl_coroutine
770 internal::ForwardAwaiter forwardCoro(HttpRequestPtr req,
771 std::string hostString =
"",
774 return internal::ForwardAwaiter(std::move(req),
775 std::move(hostString),
810 const std::string &keyPath) = 0;
816 const std::vector<std::pair<std::string, std::string>>
844 const std::vector<std::string> &dependencies,
845 const Json::Value &config) = 0;
865 const std::string &ip,
868 const std::string &certFile =
"",
869 const std::string &keyFile =
"",
870 bool useOldTLS =
false,
871 const std::vector<std::pair<std::string, std::string>> &sslConfCmds =
888 const size_t timeout = 0,
889 Cookie::SameSite sameSite = Cookie::SameSite::kNull,
890 const std::string &cookieKey =
"JSESSIONID",
892 std::function<std::string()> idGeneratorCallback =
nullptr) = 0;
903 const std::chrono::duration<double> &timeout,
904 Cookie::SameSite sameSite = Cookie::SameSite::kNull,
905 const std::string &cookieKey =
"JSESSIONID",
907 std::function<std::string()> idGeneratorCallback =
nullptr)
913 idGeneratorCallback);
921 const AdviceStartSessionCallback &advice) = 0;
928 const AdviceDestroySessionCallback &advice) = 0;
953 const std::vector<std::pair<std::string, std::string>> &headers) = 0;
974 const std::string &uriPrefix,
975 const std::string &defaultContentType =
"",
976 const std::string &alias =
"",
977 bool isCaseSensitive =
false,
978 bool allowAll =
true,
979 bool isRecursive =
true,
980 const std::vector<std::string> &middlewareNames = {}) = 0;
1008 const std::vector<std::string> &types) = 0;
1010#if !defined(_WIN32) && !TARGET_OS_IOS
1026 const std::vector<std::string> &libPaths,
1027 const std::string &outputPath =
"") = 0;
1047 size_t maxConnectionsPerIP) = 0;
1090 const std::string &logPath,
1091 const std::string &logfileBaseName =
"",
1092 size_t logSize = 100000000,
1093 size_t maxFiles = 0,
1094 bool useSpdlog =
false) = 0;
1197 const std::chrono::duration<double> &timeout)
1211 const std::string &server) = 0;
1239 const size_t number) = 0;
1252 const size_t number) = 0;
1302 size_t maxSize) = 0;
1325 const std::function<
void()> &handler) = 0;
1338 const std::function<
void()> &handler) = 0;
1377 const std::string &implicitPageFile) = 0;
1392 const std::string &name =
"default") = 0;
1400 const std::string &name =
"default") = 0;
1414 const
std::
string &name =
"default") = 0;
1422 const
std::
string &name =
"default") = 0;
1432 size_t limit) noexcept = 0;
1446 bool enable) noexcept = 0;
1465 unsigned int precision,
1466 const
std::
string &precisionType =
"significant") noexcept = 0;
1472 virtual const
std::pair<
unsigned int,
std::
string> &
1497 const
std::
string &host,
1498 unsigned short port,
1499 const
std::
string &databaseName,
1500 const
std::
string &userName,
1501 const
std::
string &password,
1502 size_t connectionNum = 1,
1503 const
std::
string &filename =
"",
1504 const
std::
string &name =
"default",
1505 bool isFast = false,
1506 const
std::
string &characterSet =
"",
1507 double timeout = -1.0,
1508 bool autoBatch = false) = 0;
1526 const
std::
string &ip,
1527 unsigned short port,
1528 const
std::
string &name =
"default",
1529 const
std::
string &password =
"",
1530 size_t connectionNum = 1,
1531 bool isFast = false,
1532 double timeout = -1.0,
1533 unsigned int db = 0,
1534 const
std::
string &username =
"") = 0;
1602 const
std::
string &ext,
1603 const
std::
string &mime) = 0;
1606 virtual
bool isCompressedRequestEnabled() const = 0;
1610 virtual int64_t getConnectionCount() const = 0;
1618 std::function<
void(
int)> cb) = 0;
1626 std::function<
void(
int)> cb) = 0;
1635 std::function<
void(const trantor::TcpConnectionPtr &)> cb) = 0;
1638 virtual
bool isRequestStreamEnabled() const = 0;
1641 virtual
void registerHttpController(
1642 const
std::
string &pathPattern,
1643 const internal::HttpBinderBasePtr &binder,
1644 const
std::vector<HttpMethod> &validMethods = {},
1645 const std::vector<std::string> &middlewareNames = {},
1646 const std::string &handlerName =
"") = 0;
1647 virtual void registerHttpControllerViaRegex(
1648 const std::string ®Exp,
1649 const internal::HttpBinderBasePtr &binder,
1650 const std::vector<HttpMethod> &validMethods,
1651 const std::vector<std::string> &middlewareNames,
1652 const std::string &handlerName) = 0;
1660#ifdef __cpp_impl_coroutine
1663inline void ForwardAwaiter::await_suspend(
1664 std::coroutine_handle<> handle)
noexcept
1668 [
this, handle](
const drogon::HttpResponsePtr &resp) {
static void setSingleInstance(const std::shared_ptr< DrObjectBase > &ins)
Set a singleton object into the map.
Definition HttpAppFramework.h:113
virtual HttpAppFramework & setCustomErrorHandler(std::function< HttpResponsePtr(HttpStatusCode, const HttpRequestPtr &req)> &&resp_generator)=0
Set custom error handler.
virtual HttpAppFramework & setStaticFilesCacheTime(int cacheTime)=0
Set the time in which the static file response is cached in memory.
virtual orm::DbClientPtr getDbClient(const std::string &name="default")=0
Get a database client by name.
virtual HttpAppFramework & registerPreHandlingAdvice(const std::function< void(const HttpRequestPtr &, AdviceCallback &&, AdviceChainCallback &&)> &advice)=0
Register an advice called before the request is handled.
virtual HttpAppFramework & setThreadNum(size_t threadNum)=0
Set the number of threads for IO event loops.
virtual HttpAppFramework & setJsonParserStackLimit(size_t limit) noexcept=0
Set the maximum stack depth of the json parser when reading a json string, the default value is 1000.
virtual HttpAppFramework & registerCustomExtensionMime(const std::string &ext, const std::string &mime)=0
Adds a new custom extension to MIME type mapping.
virtual HttpAppFramework & registerWebSocketController(const std::string &pathName, const std::string &ctrlName, const std::vector< internal::HttpConstraint > &constraints={})=0
Register a WebSocketController into the framework.
virtual PluginBase * getPlugin(const std::string &name)=0
the plugin object registered in the framework
virtual HttpAppFramework & registerSessionStartAdvice(const AdviceStartSessionCallback &advice)=0
Register an advice called when starting a new session.
virtual const std::string & getUploadPath() const =0
Get the path to store uploaded files.
virtual void addPlugin(const std::string &name, const std::vector< std::string > &dependencies, const Json::Value &config)=0
Add a plugin.
virtual HttpAppFramework & setImplicitPageEnable(bool useImplicitPage)=0
Set to enable implicit pages, enabled by default.
virtual const std::string & getDocumentRoot() const =0
Get the document root directory.
HttpAppFramework & enableSession(const std::chrono::duration< double > &timeout, Cookie::SameSite sameSite=Cookie::SameSite::kNull, const std::string &cookieKey="JSESSIONID", int maxAge=-1, std::function< std::string()> idGeneratorCallback=nullptr)
A wrapper of the above method.
Definition HttpAppFramework.h:902
virtual bool isUnicodeEscapingUsedInJson() const noexcept=0
Check if the unicode escaping is used in the json string of HTTP requests and responses.
virtual HttpAppFramework & setClientMaxBodySize(size_t maxSize)=0
Set the max body size of the requests received by drogon.
virtual bool supportSSL() const =0
Return true is drogon supports SSL(https).
virtual HttpAppFramework & enableRunAsDaemon()=0
Make the application run as a daemon.
virtual HttpAppFramework & setLogLevel(trantor::Logger::LogLevel level)=0
Set the log level.
virtual HttpAppFramework & enableServerHeader(bool flag)=0
Control if the 'Server' header is added to each HTTP response.
virtual HttpAppFramework & setClientMaxWebSocketMessageSize(size_t maxSize)=0
Set the max size of messages sent by WebSocket client.
virtual HttpAppFramework & setFileTypes(const std::vector< std::string > &types)=0
Set types of files that can be downloaded.
virtual HttpAppFramework & enableSession(const size_t timeout=0, Cookie::SameSite sameSite=Cookie::SameSite::kNull, const std::string &cookieKey="JSESSIONID", int maxAge=-1, std::function< std::string()> idGeneratorCallback=nullptr)=0
Enable sessions supporting.
virtual HttpAppFramework & enableSendfile(bool sendFile)=0
Enable the sendfile system call in linux.
virtual std::shared_ptr< PluginBase > getSharedPlugin(const std::string &name)=0
Get the shared_ptr plugin object registered in the framework.
virtual HttpAppFramework & loadConfigJson(const Json::Value &data) noexcept(false)=0
Load the configuration from a Json::Value Object.
virtual void run()=0
Run the event loop.
virtual HttpAppFramework & setCustom404Page(const HttpResponsePtr &resp, bool set404=true)=0
Set custom 404 page.
virtual HttpAppFramework & registerHttpResponseCreationAdvice(const std::function< void(const HttpResponsePtr &)> &advice)=0
Register an advice for new HTTP responses.
virtual bool isImplicitPageEnabled() const =0
Return true if implicit pages are enabled.
virtual HttpAppFramework & setMaxConnectionNumPerIP(size_t maxConnectionsPerIP)=0
Set the maximum number of connections per remote IP.
virtual HttpAppFramework & registerPreSendingAdvice(const std::function< void(const HttpRequestPtr &, const HttpResponsePtr &)> &advice)=0
Register an advice called before a response is sent to the client.
virtual size_t getJsonParserStackLimit() const noexcept=0
Get the maximum stack depth of the json parser when reading a json string.
HttpAppFramework & registerHandlerViaRegex(const std::string ®Exp, FUNCTION &&function, const std::vector< internal::HttpConstraint > &constraints={}, const std::string &handlerName="")
Register a handler into the framework via a regular expression.
Definition HttpAppFramework.h:586
virtual HttpAppFramework & registerPostRoutingAdvice(const std::function< void(const HttpRequestPtr &)> &advice)=0
Register an observer called after routing.
virtual HttpAppFramework & registerNewConnectionAdvice(const std::function< bool(const trantor::InetAddress &, const trantor::InetAddress &)> &advice)=0
Register an advice for new connections.
static HttpAppFramework & instance()
Get the instance of HttpAppFramework.
HttpAppFramework & registerMiddleware(const std::shared_ptr< T > &middlewarePtr)
Register middleware objects created and initialized by the user.
Definition HttpAppFramework.h:709
virtual const std::shared_ptr< trantor::Resolver > & getResolver() const =0
Get the DNS resolver.
virtual HttpAppFramework & registerPostRoutingAdvice(const std::function< void(const HttpRequestPtr &, AdviceCallback &&, AdviceChainCallback &&)> &advice)=0
Register an advice called after routing.
virtual HttpAppFramework & registerSessionDestroyAdvice(const AdviceDestroySessionCallback &advice)=0
Register an advice called when destroying a session.
virtual HttpAppFramework & setUploadPath(const std::string &uploadPath)=0
Set the path to store uploaded files.
virtual const std::string & getImplicitPage() const =0
Get the implicit HTML page.
virtual HttpAppFramework & setHomePage(const std::string &homePageFile)=0
virtual HttpAppFramework & reloadSSLFiles()=0
virtual const Json::Value & getCustomConfig() const =0
Get the custom configuration defined by users in the configuration file.
virtual HttpAppFramework & registerHttpSimpleController(const std::string &pathName, const std::string &ctrlName, const std::vector< internal::HttpConstraint > &constraints={})=0
Register a HttpSimpleController object into the framework.
virtual HttpAppFramework & createDbClient(const std::string &dbType, const std::string &host, unsigned short port, const std::string &databaseName, const std::string &userName, const std::string &password, size_t connectionNum=1, const std::string &filename="", const std::string &name="default", bool isFast=false, const std::string &characterSet="", double timeout=-1.0, bool autoBatch=false)=0
Create a database client.
virtual HttpAppFramework & setDocumentRoot(const std::string &rootPath)=0
Set the root path of HTTP document, default path is ./.
virtual HttpAppFramework & setMaxConnectionNum(size_t maxConnections)=0
Set the maximum number of all connections.
virtual HttpAppFramework & registerPreRoutingAdvice(const std::function< void(const HttpRequestPtr &, AdviceCallback &&, AdviceChainCallback &&)> &advice)=0
Register an advice called before routing.
virtual HttpAppFramework & enableDynamicViewsLoading(const std::vector< std::string > &libPaths, const std::string &outputPath="")=0
Enable supporting for dynamic views loading.
HttpAppFramework & registerFilter(const std::shared_ptr< T > &filterPtr)
Register filter objects created and initialized by the user.
Definition HttpAppFramework.h:692
virtual bool isBrotliEnabled() const =0
Return true if brotli is enabled.
virtual HttpAppFramework & setSSLConfigCommands(const std::vector< std::pair< std::string, std::string > > &sslConfCmds)=0
virtual bool reusePort() const =0
Return if the ReusePort mode is enabled.
virtual const std::function< HttpResponsePtr(HttpStatusCode, const HttpRequestPtr &req)> & getCustomErrorHandler() const =0
Get custom error handler.
virtual HttpAppFramework & setAfterAcceptSockOptCallback(std::function< void(int)> cb)=0
Set the after accept setsockopt callback.
virtual HttpAppFramework & disableSession()=0
Disable sessions supporting.
virtual HttpAppFramework & setFloatPrecisionInJson(unsigned int precision, const std::string &precisionType="significant") noexcept=0
Set the float precision in Json string of HTTP requests or responses with json content.
virtual int staticFilesCacheTime() const =0
Get the time set by the above method.
virtual HttpAppFramework & setExceptionHandler(ExceptionHandler handler)=0
handler will be called upon an exception escapes a request handler
virtual HttpAppFramework & setPipeliningRequestsNumber(const size_t number)=0
virtual HttpAppFramework & setServerHeaderField(const std::string &server)=0
Set the 'server' header field in each response sent by drogon.
virtual HttpAppFramework & setBeforeListenSockOptCallback(std::function< void(int)> cb)=0
Set the before listen setsockopt callback.
HttpAppFramework & registerController(const std::shared_ptr< T > &ctrlPtr)
Register controller objects created and initialized by the user.
Definition HttpAppFramework.h:672
virtual HttpAppFramework & createRedisClient(const std::string &ip, unsigned short port, const std::string &name="default", const std::string &password="", size_t connectionNum=1, bool isFast=false, double timeout=-1.0, unsigned int db=0, const std::string &username="")=0
Create a redis client.
virtual HttpAppFramework & setBrStatic(bool useGzipStatic)=0
Set the br_static option.
virtual bool areAllDbClientsAvailable() const noexcept=0
Check if all database clients in the framework are available (connect to the database successfully).
virtual HttpAppFramework & setTermSignalHandler(const std::function< void()> &handler)=0
Set the TERM Signal Handler. This method provides a way to users for exiting program gracefully....
virtual void addPlugins(const Json::Value &configs)=0
Add plugins.
virtual trantor::EventLoop * getIOLoop(size_t id) const =0
Get an IO loop with id. E.g. 0 <= id < #Total thread-loops.
virtual HttpAppFramework & enableRelaunchOnError()=0
Make the application restart after crashing.
virtual nosql::RedisClientPtr getFastRedisClient(const std::string &name="default")=0
Get a 'fast' redis client by name.
virtual HttpAppFramework & enableBrotli(bool useBrotli)=0
Enable brotli compression.
virtual HttpAppFramework & setLogLocalTime(bool on)=0
Set the log time display.
virtual HttpAppFramework & setIdleConnectionTimeout(size_t timeout)=0
Set the lifetime of the connection without read or write.
virtual void quit()=0
Quit the event loop.
virtual HttpAppFramework & setGzipStatic(bool useGzipStatic)=0
Set the gzip_static option.
virtual bool isRunning()=0
Return true if the framework is running.
virtual std::vector< HttpHandlerInfo > getHandlersInfo() const =0
Get information about the handlers registered to drogon.
virtual HttpAppFramework & setClientMaxMemoryBodySize(size_t maxSize)=0
Set the maximum body size in memory of HTTP requests received by drogon.
virtual nosql::RedisClientPtr getRedisClient(const std::string &name="default")=0
Get a redis client by name.
virtual HttpAppFramework & setUnicodeEscapingInJson(bool enable) noexcept=0
This method is to enable or disable the unicode escaping (\u) in the json string of HTTP responses or...
virtual const ExceptionHandler & getExceptionHandler() const =0
returns the excaption handler
virtual HttpAppFramework & setupFileLogger()=0
Setup output of logs to files.
virtual HttpAppFramework & registerPostHandlingAdvice(const std::function< void(const HttpRequestPtr &, const HttpResponsePtr &)> &advice)=0
Register an advice called after the request is handled.
virtual void enableReusePort(bool enable=true)=0
Enable ReusePort mode or not. If the mode is enabled, one can run multiple processes listening to the...
virtual HttpAppFramework & registerPreRoutingAdvice(const std::function< void(const HttpRequestPtr &)> &advice)=0
Register an observer called before routing.
virtual HttpAppFramework & setLogPath(const std::string &logPath, const std::string &logfileBaseName="", size_t logSize=100000000, size_t maxFiles=0, bool useSpdlog=false)=0
Set the output path of logs.
virtual HttpAppFramework & registerPreHandlingAdvice(const std::function< void(const HttpRequestPtr &)> &advice)=0
Register an observer called before the request is handled.
virtual orm::DbClientPtr getFastDbClient(const std::string &name="default")=0
Get a 'fast' database client by name.
virtual std::vector< trantor::InetAddress > getListeners() const =0
Get the addresses of listeners.
virtual const std::pair< unsigned int, std::string > & getFloatPrecisionInJson() const noexcept=0
Get the float precision set by the above method.
HttpAppFramework & registerHandler(const std::string &pathPattern, FUNCTION &&function, const std::vector< internal::HttpConstraint > &constraints={}, const std::string &handlerName="")
Register a handler into the framework.
Definition HttpAppFramework.h:535
virtual HttpAppFramework & disableSigtermHandling()=0
Disable the handling of SIGTERM signal.
virtual HttpAppFramework & enableDateHeader(bool flag)=0
Control if the 'Date' header is added to each HTTP response.
virtual HttpAppFramework & registerSyncAdvice(const std::function< HttpResponsePtr(const HttpRequestPtr &)> &advice)=0
Register a synchronous advice.
virtual void forward(const HttpRequestPtr &req, std::function< void(const HttpResponsePtr &)> &&callback, const std::string &hostString="", double timeout=0)=0
Forward the http request.
virtual HttpAppFramework & setIntSignalHandler(const std::function< void()> &handler)=0
Set the INT Signal Handler. This method provides a way to users for exiting program gracefully....
virtual HttpAppFramework & setImplicitPage(const std::string &implicitPageFile)=0
Set the page which would the server load in if it detects that the user requested a directory.
virtual size_t getThreadNum() const =0
Get the number of threads for IO event loops.
virtual HttpAppFramework & registerWebSocketControllerRegex(const std::string ®Exp, const std::string &ctrlName, const std::vector< internal::HttpConstraint > &constraints=std::vector< internal::HttpConstraint >{})=0
Register a WebSocketController into the framework.
virtual HttpAppFramework & setConnectionCallback(std::function< void(const trantor::TcpConnectionPtr &)> cb)=0
Set the client disconnect or connect callback.
virtual HttpAppFramework & setDefaultHandler(DefaultHandler handler)=0
virtual HttpAppFramework & enableGzip(bool useGzip)=0
Enable gzip compression.
virtual HttpAppFramework & loadConfigJson(Json::Value &&data) noexcept(false)=0
Load the configuration from a Json::Value Object.
std::shared_ptr< T > getSharedPlugin()
Get the shared_ptr plugin object registered in the framework.
Definition HttpAppFramework.h:238
T * getPlugin()
Get the plugin object registered in the framework.
Definition HttpAppFramework.h:219
virtual HttpAppFramework & setKeepaliveRequestsNumber(const size_t number)=0
virtual HttpAppFramework & addListener(const std::string &ip, uint16_t port, bool useSSL=false, const std::string &certFile="", const std::string &keyFile="", bool useOldTLS=false, const std::vector< std::pair< std::string, std::string > > &sslConfCmds={})=0
Add a listener for http or https service.
virtual HttpAppFramework & setSSLFiles(const std::string &certPath, const std::string &keyPath)=0
HttpAppFramework & setIdleConnectionTimeout(const std::chrono::duration< double > &timeout)
A wrapper of the above method.
Definition HttpAppFramework.h:1196
virtual const std::string & getHomePage() const =0
Get homepage, default is "index.html".
virtual HttpAppFramework & loadConfigFile(const std::string &fileName) noexcept(false)=0
Load the configuration file with json format.
virtual size_t getCurrentThreadIndex() const =0
Get the Current Thread Index whose range is [0, the total number of IO threads].
virtual HttpAppFramework & addALocation(const std::string &uriPrefix, const std::string &defaultContentType="", const std::string &alias="", bool isCaseSensitive=false, bool allowAll=true, bool isRecursive=true, const std::vector< std::string > &middlewareNames={})=0
Add a location of static files for GET requests.
virtual trantor::EventLoop * getLoop() const =0
Get the main event loop of the framework;.
virtual HttpAppFramework & registerBeginningAdvice(const std::function< void()> &advice)=0
Register a beginning advice.
virtual HttpAppFramework & setStaticFileHeaders(const std::vector< std::pair< std::string, std::string > > &headers)=0
Set the Static File Headers.
virtual bool isGzipEnabled() const =0
Return true if gzip is enabled.
The base class for HTTP controllers.
Definition HttpController.h:48
The abstract base class for HTTP simple controllers.
Definition HttpSimpleController.h:37
The abstract base class for plugins.
Definition Plugin.h:37
The abstract base class for WebSocket controllers.
Definition WebSocketController.h:42
Drogon Test is a minimal effort test framework developed because the major C++ test frameworks doesn'...
Definition Attribute.h:23
HttpAppFramework & app()
A wrapper of the instance() method.
Definition HttpAppFramework.h:1656