|
drogon
C++14/17-based HTTP application framework
|


Public Member Functions | |
| virtual void | run ()=0 |
| Run the event loop. | |
| virtual bool | isRunning ()=0 |
| Return true if the framework is running. | |
| virtual void | quit ()=0 |
| Quit the event loop. | |
| virtual trantor::EventLoop * | getLoop () const =0 |
| Get the main event loop of the framework;. | |
| virtual trantor::EventLoop * | getIOLoop (size_t id) const =0 |
| Get an IO loop with id. E.g. 0 <= id < #Total thread-loops. | |
| virtual HttpAppFramework & | setCustom404Page (const HttpResponsePtr &resp, bool set404=true)=0 |
| Set custom 404 page. | |
| virtual HttpAppFramework & | setCustomErrorHandler (std::function< HttpResponsePtr(HttpStatusCode, const HttpRequestPtr &req)> &&resp_generator)=0 |
| Set custom error handler. | |
| HttpAppFramework & | setCustomErrorHandler (std::function< HttpResponsePtr(HttpStatusCode)> &&resp_generator) |
| virtual const std::function< HttpResponsePtr(HttpStatusCode, const HttpRequestPtr &req)> & | getCustomErrorHandler () const =0 |
| Get custom error handler. | |
| template<typename T> | |
| T * | getPlugin () |
| Get the plugin object registered in the framework. | |
| template<typename T> | |
| std::shared_ptr< T > | getSharedPlugin () |
| Get the shared_ptr plugin object registered in the framework. | |
| virtual PluginBase * | getPlugin (const std::string &name)=0 |
| the plugin object registered in the framework | |
| virtual std::shared_ptr< PluginBase > | getSharedPlugin (const std::string &name)=0 |
| Get the shared_ptr plugin object registered in the framework. | |
| virtual HttpAppFramework & | registerBeginningAdvice (const std::function< void()> &advice)=0 |
| Register a beginning advice. | |
| virtual HttpAppFramework & | registerNewConnectionAdvice (const std::function< bool(const trantor::InetAddress &, const trantor::InetAddress &)> &advice)=0 |
| Register an advice for new connections. | |
| virtual HttpAppFramework & | registerHttpResponseCreationAdvice (const std::function< void(const HttpResponsePtr &)> &advice)=0 |
| Register an advice for new HTTP responses. | |
| virtual HttpAppFramework & | registerSyncAdvice (const std::function< HttpResponsePtr(const HttpRequestPtr &)> &advice)=0 |
| Register a synchronous advice. | |
| virtual HttpAppFramework & | registerPreRoutingAdvice (const std::function< void(const HttpRequestPtr &, AdviceCallback &&, AdviceChainCallback &&)> &advice)=0 |
| Register an advice called before routing. | |
| virtual HttpAppFramework & | registerPreRoutingAdvice (const std::function< void(const HttpRequestPtr &)> &advice)=0 |
| Register an observer called before routing. | |
| virtual HttpAppFramework & | registerPostRoutingAdvice (const std::function< void(const HttpRequestPtr &, AdviceCallback &&, AdviceChainCallback &&)> &advice)=0 |
| Register an advice called after routing. | |
| virtual HttpAppFramework & | registerPostRoutingAdvice (const std::function< void(const HttpRequestPtr &)> &advice)=0 |
| Register an observer called after routing. | |
| virtual HttpAppFramework & | registerPreHandlingAdvice (const std::function< void(const HttpRequestPtr &, AdviceCallback &&, AdviceChainCallback &&)> &advice)=0 |
| Register an advice called before the request is handled. | |
| virtual HttpAppFramework & | registerPreHandlingAdvice (const std::function< void(const HttpRequestPtr &)> &advice)=0 |
| Register an observer called before the request is handled. | |
| virtual HttpAppFramework & | registerPostHandlingAdvice (const std::function< void(const HttpRequestPtr &, const HttpResponsePtr &)> &advice)=0 |
| Register an advice called after the request is handled. | |
| 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 HttpAppFramework & | setupFileLogger ()=0 |
| Setup output of logs to files. | |
| virtual HttpAppFramework & | loadConfigFile (const std::string &fileName) noexcept(false)=0 |
| Load the configuration file with json format. | |
| virtual HttpAppFramework & | loadConfigJson (const Json::Value &data) noexcept(false)=0 |
| Load the configuration from a Json::Value Object. | |
| virtual HttpAppFramework & | loadConfigJson (Json::Value &&data) noexcept(false)=0 |
| Load the configuration from a Json::Value Object. | |
| 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. | |
| template<typename FUNCTION> | |
| HttpAppFramework & | registerHandler (const std::string &pathPattern, FUNCTION &&function, const std::vector< internal::HttpConstraint > &constraints={}, const std::string &handlerName="") |
| Register a handler into the framework. | |
| template<typename FUNCTION> | |
| 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. | |
| 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 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. | |
| template<typename T> | |
| HttpAppFramework & | registerController (const std::shared_ptr< T > &ctrlPtr) |
| Register controller objects created and initialized by the user. | |
| template<typename T> | |
| HttpAppFramework & | registerFilter (const std::shared_ptr< T > &filterPtr) |
| Register filter objects created and initialized by the user. | |
| template<typename T> | |
| HttpAppFramework & | registerMiddleware (const std::shared_ptr< T > &middlewarePtr) |
| Register middleware objects created and initialized by the user. | |
| virtual HttpAppFramework & | setDefaultHandler (DefaultHandler handler)=0 |
| 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 std::vector< HttpHandlerInfo > | getHandlersInfo () const =0 |
| Get information about the handlers registered to drogon. | |
| virtual const Json::Value & | getCustomConfig () const =0 |
| Get the custom configuration defined by users in the configuration file. | |
| virtual HttpAppFramework & | setThreadNum (size_t threadNum)=0 |
| Set the number of threads for IO event loops. | |
| virtual size_t | getThreadNum () const =0 |
| Get the number of threads for IO event loops. | |
| virtual HttpAppFramework & | setSSLFiles (const std::string &certPath, const std::string &keyPath)=0 |
| virtual HttpAppFramework & | setSSLConfigCommands (const std::vector< std::pair< std::string, std::string > > &sslConfCmds)=0 |
| virtual HttpAppFramework & | reloadSSLFiles ()=0 |
| virtual void | addPlugins (const Json::Value &configs)=0 |
| Add plugins. | |
| virtual void | addPlugin (const std::string &name, const std::vector< std::string > &dependencies, const Json::Value &config)=0 |
| Add a plugin. | |
| 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 & | 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. | |
| 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. | |
| virtual HttpAppFramework & | registerSessionStartAdvice (const AdviceStartSessionCallback &advice)=0 |
| Register an advice called when starting a new session. | |
| virtual HttpAppFramework & | registerSessionDestroyAdvice (const AdviceDestroySessionCallback &advice)=0 |
| Register an advice called when destroying a session. | |
| virtual HttpAppFramework & | disableSession ()=0 |
| Disable sessions supporting. | |
| virtual HttpAppFramework & | setDocumentRoot (const std::string &rootPath)=0 |
| Set the root path of HTTP document, default path is ./. | |
| virtual const std::string & | getDocumentRoot () const =0 |
| Get the document root directory. | |
| virtual HttpAppFramework & | setStaticFileHeaders (const std::vector< std::pair< std::string, std::string > > &headers)=0 |
| Set the Static File Headers. | |
| 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 HttpAppFramework & | setUploadPath (const std::string &uploadPath)=0 |
| Set the path to store uploaded files. | |
| virtual const std::string & | getUploadPath () const =0 |
| Get the path to store uploaded files. | |
| virtual HttpAppFramework & | setFileTypes (const std::vector< std::string > &types)=0 |
| Set types of files that can be downloaded. | |
| virtual HttpAppFramework & | enableDynamicViewsLoading (const std::vector< std::string > &libPaths, const std::string &outputPath="")=0 |
| Enable supporting for dynamic views loading. | |
| virtual HttpAppFramework & | setMaxConnectionNum (size_t maxConnections)=0 |
| Set the maximum number of all connections. | |
| virtual HttpAppFramework & | setMaxConnectionNumPerIP (size_t maxConnectionsPerIP)=0 |
| Set the maximum number of connections per remote IP. | |
| virtual HttpAppFramework & | enableRunAsDaemon ()=0 |
| Make the application run as a daemon. | |
| virtual HttpAppFramework & | disableSigtermHandling ()=0 |
| Disable the handling of SIGTERM signal. | |
| virtual HttpAppFramework & | enableRelaunchOnError ()=0 |
| Make the application restart after crashing. | |
| 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 & | setLogLevel (trantor::Logger::LogLevel level)=0 |
| Set the log level. | |
| virtual HttpAppFramework & | setLogLocalTime (bool on)=0 |
| Set the log time display. | |
| virtual HttpAppFramework & | enableSendfile (bool sendFile)=0 |
| Enable the sendfile system call in linux. | |
| virtual HttpAppFramework & | enableGzip (bool useGzip)=0 |
| Enable gzip compression. | |
| virtual bool | isGzipEnabled () const =0 |
| Return true if gzip is enabled. | |
| virtual HttpAppFramework & | enableBrotli (bool useBrotli)=0 |
| Enable brotli compression. | |
| virtual bool | isBrotliEnabled () const =0 |
| Return true if brotli is enabled. | |
| virtual HttpAppFramework & | setStaticFilesCacheTime (int cacheTime)=0 |
| Set the time in which the static file response is cached in memory. | |
| virtual int | staticFilesCacheTime () const =0 |
| Get the time set by the above method. | |
| virtual HttpAppFramework & | setIdleConnectionTimeout (size_t timeout)=0 |
| Set the lifetime of the connection without read or write. | |
| HttpAppFramework & | setIdleConnectionTimeout (const std::chrono::duration< double > &timeout) |
| A wrapper of the above method. | |
| virtual HttpAppFramework & | setServerHeaderField (const std::string &server)=0 |
| Set the 'server' header field in each response sent by drogon. | |
| virtual HttpAppFramework & | enableServerHeader (bool flag)=0 |
| Control if the 'Server' header is added to each HTTP response. | |
| virtual HttpAppFramework & | enableDateHeader (bool flag)=0 |
| Control if the 'Date' header is added to each HTTP response. | |
| virtual HttpAppFramework & | setKeepaliveRequestsNumber (const size_t number)=0 |
| virtual HttpAppFramework & | setPipeliningRequestsNumber (const size_t number)=0 |
| virtual HttpAppFramework & | setGzipStatic (bool useGzipStatic)=0 |
| Set the gzip_static option. | |
| virtual HttpAppFramework & | setBrStatic (bool useGzipStatic)=0 |
| Set the br_static option. | |
| virtual HttpAppFramework & | setClientMaxBodySize (size_t maxSize)=0 |
| Set the max body size of the requests received by drogon. | |
| virtual HttpAppFramework & | setClientMaxMemoryBodySize (size_t maxSize)=0 |
| Set the maximum body size in memory of HTTP requests received by drogon. | |
| virtual HttpAppFramework & | setClientMaxWebSocketMessageSize (size_t maxSize)=0 |
| Set the max size of messages sent by WebSocket client. | |
| virtual HttpAppFramework & | setHomePage (const std::string &homePageFile)=0 |
| 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. When the TERM signal is received after app().run() is called, the handler is invoked. Drogon uses a default signal handler for the TERM signal, which calls the 'app().quit()' method when the TERM signal is received. | |
| 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. When the INT signal is received after app().run() is called, the handler is invoked. Drogon uses a default signal handler for the INT signal, which calls the 'app().quit()' method when the INT signal is received. | |
| virtual const std::string & | getHomePage () const =0 |
| Get homepage, default is "index.html". | |
| virtual HttpAppFramework & | setImplicitPageEnable (bool useImplicitPage)=0 |
| Set to enable implicit pages, enabled by default. | |
| virtual bool | isImplicitPageEnabled () const =0 |
| Return true if implicit pages are enabled. | |
| 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 const std::string & | getImplicitPage () const =0 |
| Get the implicit HTML page. | |
| virtual orm::DbClientPtr | getDbClient (const std::string &name="default")=0 |
| Get a database client by name. | |
| virtual orm::DbClientPtr | getFastDbClient (const std::string &name="default")=0 |
| Get a 'fast' database client by name. | |
| virtual bool | areAllDbClientsAvailable () const noexcept=0 |
| Check if all database clients in the framework are available (connect to the database successfully). | |
| virtual nosql::RedisClientPtr | getRedisClient (const std::string &name="default")=0 |
| Get a redis client by name. | |
| virtual nosql::RedisClientPtr | getFastRedisClient (const std::string &name="default")=0 |
| Get a 'fast' redis client by name. | |
| 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 size_t | getJsonParserStackLimit () const noexcept=0 |
| Get the maximum stack depth of the json parser when reading a json string. | |
| 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 requests. it works (disable successfully) when the version of JsonCpp >= 1.9.3, the unicode escaping is enabled by default. | |
| virtual bool | isUnicodeEscapingUsedInJson () const noexcept=0 |
| Check if the unicode escaping is used in the json string of HTTP requests and responses. | |
| 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 const std::pair< unsigned int, std::string > & | getFloatPrecisionInJson () const noexcept=0 |
| Get the float precision set by the above method. | |
| 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 & | addDbClient (const orm::DbConfig &config)=0 |
| 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 const std::shared_ptr< trantor::Resolver > & | getResolver () const =0 |
| Get the DNS resolver. | |
| virtual bool | supportSSL () const =0 |
| Return true is drogon supports SSL(https). | |
| virtual size_t | getCurrentThreadIndex () const =0 |
| Get the Current Thread Index whose range is [0, the total number of IO threads]. | |
| virtual std::vector< trantor::InetAddress > | getListeners () const =0 |
| Get the addresses of listeners. | |
| 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 same port at the same time. If this method is not called, the feature is disabled. | |
| virtual bool | reusePort () const =0 |
| Return if the ReusePort mode is enabled. | |
| virtual HttpAppFramework & | setExceptionHandler (ExceptionHandler handler)=0 |
| handler will be called upon an exception escapes a request handler | |
| virtual const ExceptionHandler & | getExceptionHandler () const =0 |
| returns the excaption handler | |
| virtual HttpAppFramework & | registerCustomExtensionMime (const std::string &ext, const std::string &mime)=0 |
| Adds a new custom extension to MIME type mapping. | |
| virtual HttpAppFramework & | enableCompressedRequest (bool enable=true)=0 |
| virtual bool | isCompressedRequestEnabled () const =0 |
| virtual int64_t | getConnectionCount () const =0 |
| virtual HttpAppFramework & | setBeforeListenSockOptCallback (std::function< void(int)> cb)=0 |
| Set the before listen setsockopt callback. | |
| virtual HttpAppFramework & | setAfterAcceptSockOptCallback (std::function< void(int)> cb)=0 |
| Set the after accept setsockopt callback. | |
| virtual HttpAppFramework & | setConnectionCallback (std::function< void(const trantor::TcpConnectionPtr &)> cb)=0 |
| Set the client disconnect or connect callback. | |
| virtual HttpAppFramework & | enableRequestStream (bool enable=true)=0 |
| virtual bool | isRequestStreamEnabled () const =0 |
Static Public Member Functions | |
| static HttpAppFramework & | instance () |
| Get the instance of HttpAppFramework. | |
|
pure virtual |
Add a location of static files for GET requests.
| uriPrefix | The URI prefix of the location prefixed with "/" |
| defaultContentType | The default content type of the static files without an extension. |
| alias | The location in file system, if it is prefixed with "/", it presents an absolute path, otherwise it presents a relative path to the document_root path. |
| isCaseSensitive | |
| allowAll | If it is set to false, only static files with a valid extension can be accessed. |
| isRecursive | If it is set to false, files in sub directories can't be accessed. |
| middlewareNames | The list of middlewares which acting on the location. |
|
pure virtual |
Add a listener for http or https service.
| ip | is the ip that the listener listens on. |
| port | is the port that the listener listens on. |
| useSSL | if the parameter is true, the listener is used for the https service. |
| certFile | |
| keyFile | specify the cert file and the private key file for this listener. If they are empty, the global configuration set by the above method is used. |
| useOldTLS | if true, the TLS1.0/1.1 are enabled for HTTPS connections. |
| sslConfCmds | vector of ssl configuration key/value pairs. |
|
pure virtual |
Add a plugin.
| name | Name of the plugin |
| dependencies | Names of plugins this plugin depends on |
| config | Custom config for the plugin |
|
pure virtual |
Add plugins.
| configs | The plugins array |
|
pure virtual |
Create a database client.
| dbType | The database type is one of "postgresql","mysql","sqlite3". |
| host | IP or host name. |
| port | The port on which the database server is listening. |
| databaseName | Database name |
| userName | User name |
| password | Password for the database server |
| connectionNum | The number of connections to the database server. It's valid only if isFast is false. |
| filename | The file name of sqlite3 database file. |
| name | The client name. |
| isFast | Indicates if the client is a fast database client. |
| characterSet | The character set of the database server. |
| timeout | The timeout in seconds for executing SQL queries. zero or negative value means no timeout. |
|
pure virtual |
Create a redis client.
| ip | IP of redis server. |
| port | The port on which the redis server is listening. |
| name | The client name. |
| username | Username for redis server |
| password | Password for the redis server |
| connectionNum | The number of connections to the redis server. |
| isFast | Indicates if the client is a fast database client. |
|
pure virtual |
Disable sessions supporting.
|
pure virtual |
Disable the handling of SIGTERM signal.
Enabled by default.
|
pure virtual |
Enable brotli compression.
| useBrotli | if the parameter is true, use brotli to compress the response body's content; The default value is true. |
|
pure virtual |
Control if the 'Date' header is added to each HTTP response.
|
pure virtual |
Enable supporting for dynamic views loading.
| libPaths | is a vector that contains paths to view files. |
| outputPath | is the directory where the output source files locate. If it is set to an empty string, drogon use libPaths as output paths. If the path isn't prefixed with /, it is the relative path of the current working directory. |
|
pure virtual |
Enable gzip compression.
| useGzip | if the parameter is true, use gzip to compress the response body's content; The default value is true. |
|
pure virtual |
Make the application restart after crashing.
Disabled by default.
|
pure virtual |
Enable ReusePort mode or not. If the mode is enabled, one can run multiple processes listening to the same port at the same time. If this method is not called, the feature is disabled.
|
pure virtual |
Make the application run as a daemon.
Disabled by default.
|
pure virtual |
Enable the sendfile system call in linux.
| sendFile | if the parameter is true, sendfile() system-call is used to send static files to clients; The default value is true. |
|
pure virtual |
Control if the 'Server' header is added to each HTTP response.
|
pure virtual |
Enable sessions supporting.
| timeout | The number of seconds which is the timeout of a session |
| sameSite | The default value of SameSite attribute |
| cookieKey | The key of the session cookie |
|
inline |
A wrapper of the above method.
Example: Users can set the timeout value as follows:
|
pure virtual |
Forward the http request.
| req | the HTTP request to be forwarded; |
| hostString | is the address where the request is forwarded. The following strings are valid for the parameter: |
| timeout | See the timeout parameter of the sendRequest method of the HttpClient class. this parameter is only valid when the hostString is not empty. |
| callback | is called when the response is created. |
This method can be used to implement reverse proxy or redirection on the server side.
|
pure virtual |
Get the Current Thread Index whose range is [0, the total number of IO threads].
|
pure virtual |
Get custom error handler.
|
pure virtual |
Get a database client by name.
|
pure virtual |
Get a 'fast' database client by name.
|
pure virtual |
Get a 'fast' redis client by name.
|
pure virtualnoexcept |
Get the float precision set by the above method.
|
pure virtual |
Get information about the handlers registered to drogon.
|
pure virtual |
Get homepage, default is "index.html".
|
pure virtual |
Get the implicit HTML page.
|
pure virtual |
Get an IO loop with id. E.g. 0 <= id < #Total thread-loops.
|
pure virtual |
|
pure virtual |
Get the main event loop of the framework;.
|
inline |
Get the plugin object registered in the framework.
|
pure virtual |
the plugin object registered in the framework
| name | is the class name of the plugin. |
|
pure virtual |
Get a redis client by name.
|
pure virtual |
Get the DNS resolver.
|
inline |
Get the shared_ptr plugin object registered in the framework.
|
pure virtual |
Get the shared_ptr plugin object registered in the framework.
|
static |
Get the instance of HttpAppFramework.
HttpAppFramework works at singleton mode, so any calling of this method gets the same instance; Calling drogon::HttpAppFramework::instance() can be replaced by a simple interface – drogon::app()
|
pure virtual |
Return true if implicit pages are enabled.
|
pure virtual |
Load the configuration file with json format.
| fileName | the configuration file |
|
pure virtualnoexcept |
Load the configuration from a Json::Value Object.
| data | Json::Value Object containing the configuration. |
|
pure virtualnoexcept |
Load the configuration from a Json::Value Object.
| data | rvalue reference to a Json::Value object containing the configuration. |
|
pure virtual |
Quit the event loop.
Calling this method results in stopping all network IO in the framework and interrupting the blocking of the run() method. Usually, after calling this method, the application exits (when the run() method is called in the main thread).
|
pure virtual |
Register a beginning advice.
| advice | is called immediately after the main event loop runs. |
|
inline |
Register controller objects created and initialized by the user.
Drogon can only automatically create controllers using the default constructor. Sometimes users want to be able to create controllers using constructors with parameters. Controllers created by user in this way should be registered to the framework via this method. The macro or configuration file is still valid for the path routing configuration of the controller created by users.
|
inline |
Register filter objects created and initialized by the user.
This method is similar to the above method.
|
inline |
Register a handler into the framework.
| pathPattern | When the path of a http request matches the pathPattern, the handler indicated by the function parameter is called. |
| function | indicates any type of callable object with a valid processing interface. |
| constraints | is the same as the third parameter in the above method. |
Example:
|
inline |
Register a handler into the framework via a regular expression.
| regExp | A regular expression string, when the path of a http request matches the regular expression, the handler indicated by the function parameter is called. |
| function | indicates any type of callable object with a valid processing interface. |
| constraints | is the same as the third parameter in the above method. |
| handlerName | a name for the handler. |
|
pure virtual |
Register an advice for new HTTP responses.
| advice | is called immediately when a new HTTP response is created. Users can use the callback to modify the response if they want. |
|
pure virtual |
Register a HttpSimpleController object into the framework.
| pathName | When the path of a http request is equal to the pathName, the asyncHandleHttpRequest() method of the controller is called. |
| ctrlName | is the name of the controller. It includes the namespace to which the controller belongs. |
| constraints | is a vector containing Http methods or middleware names Example: |
|
inline |
Register middleware objects created and initialized by the user.
This method is similar to the above method.
|
pure virtual |
Register an advice for new connections.
| advice | is called immediately when a new connection is established. the first parameter of it is the remote address of the new connection, the second one is the local address of it. If the advice returns a false value, drogon closes the connection. Users can use this advice to implement some security policies. |
|
pure virtual |
Register an advice called after the request is handled.
| advice | is called immediately after the request is handled and a response object is created by handlers. |
|
pure virtual |
Register an observer called after routing.
| advice | is called at the same time as the above advice. It can be thought of as an observer who cannot respond to http requests. |
|
pure virtual |
Register an advice called after routing.
| advice | is called immediately after the request matches a handler path and before any filters/middlewares applies. The parameters of the advice are same as those of the doFilter method of the Filter class. |
|
pure virtual |
Register an observer called before the request is handled.
| advice | is called at the same time as the above advice. It can be thought of as an observer who cannot respond to http requests. This advice has less overhead than the above one. If one does not intend to intercept the http request, please use this interface. |
|
pure virtual |
Register an advice called before the request is handled.
| advice | is called immediately after the request is approved by all filters/middlewares and before it is handled. The parameters of the advice are same as those of the doFilter method of the Filter class. |
|
pure virtual |
Register an observer called before routing.
| advice | is called at the same time as the above advice. It can be thought of as an observer who cannot respond to http requests. |
|
pure virtual |
Register an advice called before routing.
| advice | is called after all the synchronous advice return nullptr and before the request is routed to any handler. The parameters of the advice are same as those of the doFilter method of the Filter class. |
|
pure virtual |
Register an advice called before a response is sent to the client.
|
pure virtual |
Register an advice called when destroying a session.
| advice | is called with the session id. |
|
pure virtual |
Register an advice called when starting a new session.
| advice | is called with the session id. |
|
pure virtual |
Register a synchronous advice.
| advice | is called immediately after the request is created. If a no-empty response is returned by the advice, it is sent to the client and no handler is invoked. |
|
pure virtual |
Register a WebSocketController into the framework.
The parameters of this method are the same as those in the registerHttpSimpleController() method.
|
pure virtual |
Register a WebSocketController into the framework.
The parameters of this method are the same as those in the registerHttpSimpleController() method but using regular expression string for path.
|
pure virtual |
Reload the global cert file and private key file for https server Note: The goal of this method is not to make the framework use the new SSL path, but rather to reload the new content from the old path while the framework is still running. Typically, when our SSL is about to expire, we need to reload the SSL. The purpose of this function is to use the new SSL certificate without stopping the framework.
|
pure virtual |
Run the event loop.
Calling this method starts the IO event loops and the main loop of the application; This method can be called in the main thread or any other thread. This method blocks the current thread until the main event loop exits.
|
pure virtual |
Set the after accept setsockopt callback.
| cb | This callback will be called after accept |
|
pure virtual |
Set the before listen setsockopt callback.
| cb | This callback will be called before the listen |
|
pure virtual |
Set the br_static option.
If it is set to true, when the client requests a static file, drogon first finds the compressed file with the extension ".br" in the same path and send the compressed file to the client. The default value is true.
|
pure virtual |
Set the max body size of the requests received by drogon.
The default value is 1M.
|
pure virtual |
Set the maximum body size in memory of HTTP requests received by drogon.
The default value is "64K" bytes. If the body size of a HTTP request exceeds this limit, the body is stored to a temporary file for processing.
|
pure virtual |
Set the max size of messages sent by WebSocket client.
The default value is 128K.
|
pure virtual |
Set the client disconnect or connect callback.
| cb | This callback will be called, when the client disconnect or connect |
|
pure virtual |
Set custom 404 page.
| resp | is the object set to 404 response After calling this method, the resp object is returned by the HttpResponse::newNotFoundResponse() method. |
| set404 | if true, the status code of the resp will be set to 404 automatically |
|
pure virtual |
Set custom error handler.
| resp_generator | is invoked when an error in the framework needs to be sent to the client to provide a custom layout. |
|
pure virtual |
Register a default handler into the framework when no handler matches the request. If set, it is executed if the static file router does not find any file corresponding to the request. Thus it replaces the default 404 not found response.
| handler | function indicates any type of callable object with a valid processing interface. |
|
pure virtual |
Set the root path of HTTP document, default path is ./.
|
pure virtual |
Set types of files that can be downloaded.
Example:
|
pure virtualnoexcept |
Set the float precision in Json string of HTTP requests or responses with json content.
| precision | The maximum digits length. |
| precisionType | Must be "significant" or "decimal", defaults to "significant" that means setting max number of significant digits in string, "decimal" means setting max number of digits after "." in string |
|
pure virtual |
Set the gzip_static option.
If it is set to true, when the client requests a static file, drogon first finds the compressed file with the extension ".gz" in the same path and send the compressed file to the client. The default value is true.
|
pure virtual |
If there isn't any handler registered to the path "/", the home page file in the "document_root" is send to clients as a response to the request for "/".
|
inline |
A wrapper of the above method.
Example: Users can set the timeout value as follows:
|
pure virtual |
Set the lifetime of the connection without read or write.
| timeout | in seconds. 60 by default. Setting the timeout to 0 means that drogon does not close idle connections. |
|
pure virtual |
Set the page which would the server load in if it detects that the user requested a directory.
Set the HTML file that a directory would resolve to by default, default is "index.html"
|
pure virtual |
Set to enable implicit pages, enabled by default.
Implicit pages are used when the server detects if the user requested a directory. By default, it will try to append index.html to the path, see setImplicitPage() if you want to customize this (http://localhost/a-directory resolves to http://localhost/a-directory/index.html by default).
|
pure virtual |
Set the INT Signal Handler. This method provides a way to users for exiting program gracefully. When the INT signal is received after app().run() is called, the handler is invoked. Drogon uses a default signal handler for the INT signal, which calls the 'app().quit()' method when the INT signal is received.
| handler |
|
pure virtualnoexcept |
Set the maximum stack depth of the json parser when reading a json string, the default value is 1000.
|
pure virtual |
Set the maximum number of requests that can be served through one keep-alive connection. After the maximum number of requests are made, the connection is closed. The default value is 0 which means no limit.
|
pure virtual |
Set the log level.
| level | is one of TRACE, DEBUG, INFO, WARN. The Default value is DEBUG. |
|
pure virtual |
Set the log time display.
| on | is true to display local time, false to display UTC time. The Default value is false. |
|
pure virtual |
Set the output path of logs.
| logPath | The path to logs - logs to console if empty. |
| logfileBaseName | The base name of log files - defaults to "drogon" if empty. |
| logSize | indicates the maximum size of a log file. |
| maxFiles | max count of log file - 0 = unlimited. |
| useSpdlog | Use spdlog for logging (if compiled-in). |
|
pure virtual |
Set the maximum number of all connections.
The default value is 100000.
|
pure virtual |
Set the maximum number of connections per remote IP.
The default value is 0 which means no limit.
|
pure virtual |
Set the maximum number of unhandled requests that can be cached in pipelining buffer. The default value of 0 means no limit. After the maximum number of requests cached in pipelining buffer are made, the connection is closed.
|
pure virtual |
Set the 'server' header field in each response sent by drogon.
| server | empty string by default with which the 'server' header field is set to "Server: drogon/version string\r\n" |
|
pure virtual |
Supplies file style SSL options to SSL_CONF_cmd. Valid options are available at https://www.openssl.org/docs/manmaster/man3/SSL_CONF_cmd.html
|
pure virtual |
Set the global cert file and private key file for https These options can be configured in the configuration file.
|
pure virtual |
Set the Static File Headers.
| headers | Each pair object in the vector presents the field name and field value of a header in an static file response. |
|
pure virtual |
Set the time in which the static file response is cached in memory.
| cacheTime | in seconds. 0 means always cached, negative means no cache |
|
pure virtual |
Set the TERM Signal Handler. This method provides a way to users for exiting program gracefully. When the TERM signal is received after app().run() is called, the handler is invoked. Drogon uses a default signal handler for the TERM signal, which calls the 'app().quit()' method when the TERM signal is received.
| handler |
|
pure virtual |
Set the number of threads for IO event loops.
| threadNum | the number of threads The default value is 1, if the parameter is 0, the number is equal to the number of CPU cores. |
|
pure virtual |
Setup output of logs to files.
|
pure virtual |
Set the path to store uploaded files.
| uploadPath | is the directory where the uploaded files are stored. if it isn't prefixed with /, ./ or ../, it is relative path of document_root path, The default value is 'uploads'. |