![]() |
cutelyst 4.8.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
|
Implements a web server. More...
#include <Cutelyst/Server/server.h>

Signals | |
| void | changed () |
| void | errorOccured (const QString &error) |
| void | ready () |
| void | stopped () |
Public Member Functions | |
| Server (QObject *parent=nullptr) | |
| virtual | ~Server () |
| QString | application () const |
| bool | autoReload () const |
| int | bufferSize () const |
| QString | chdir () const |
| QString | chdir2 () const |
| QString | chownSocket () const |
| QVariantMap | config () const noexcept |
| int | cpuAffinity () const |
| int | exec (Cutelyst::Application *app=nullptr) |
| QStringList | fastcgiSocket () const |
| QString | gid () const |
| quint32 | http2HeaderTableSize () const |
| QStringList | http2Socket () const |
| bool | httpsH2 () const |
| QStringList | httpSocket () const |
| QStringList | httpsSocket () const |
| QStringList | ini () const |
| QStringList | json () const |
| bool | lazy () const |
| int | listenQueue () const |
| bool | master () const |
| bool | noInitgroups () const |
| void | parseCommandLine (const QStringList &args) |
| QString | pidfile () const |
| QString | pidfile2 () const |
| qint64 | postBuffering () const |
| qint64 | postBufferingBufsize () const |
| QString | processes () const |
| bool | reusePort () const |
| void | setApplication (const QString &application) |
| void | setAutoReload (bool enable) |
| void | setBufferSize (int size) |
| void | setChdir (const QString &chdir) |
| void | setChdir2 (const QString &chdir2) |
| void | setChownSocket (const QString &chownSocket) |
| void | setCpuAffinity (int value) |
| void | setFastcgiSocket (const QStringList &fastcgiSocket) |
| void | setGid (const QString &gid) |
| void | setHttp2HeaderTableSize (quint32 headerTableSize) |
| void | setHttp2Socket (const QStringList &http2Socket) |
| void | setHttpsH2 (bool enable) |
| void | setHttpSocket (const QStringList &httpSocket) |
| void | setHttpsSocket (const QStringList &httpsSocket) |
| void | setIni (const QStringList &files) |
| void | setJson (const QStringList &files) |
| void | setLazy (bool enable) |
| void | setListenQueue (int size) |
| void | setMaster (bool enable) |
| void | setNoInitgroups (bool enable) |
| void | setPidfile (const QString &file) |
| void | setPidfile2 (const QString &file) |
| void | setPostBuffering (qint64 size) |
| void | setPostBufferingBufsize (qint64 size) |
| void | setProcesses (const QString &process) |
| void | setReusePort (bool enable) |
| void | setSocketAccess (const QString &socketAccess) |
| void | setSocketRcvbuf (int value) |
| void | setSocketSndbuf (int value) |
| void | setSocketTimeout (int timeout) |
| void | setSoKeepalive (bool enable) |
| void | setStaticMap (const QStringList &staticMap) |
| void | setStaticMap2 (const QStringList &staticMap) |
| void | setTcpNodelay (bool enable) |
| void | setThreads (const QString &threads) |
| void | setTouchReload (const QStringList &files) |
| void | setUid (const QString &uid) |
| void | setUmask (const QString &value) |
| void | setUpgradeH2c (bool enable) |
| void | setUsingFrontendProxy (bool enable) |
| void | setWebsocketMaxSize (int value) |
| QString | socketAccess () const |
| int | socketRcvbuf () const |
| int | socketSndbuf () const |
| int | socketTimeout () const |
| bool | soKeepalive () const |
| bool | start (Cutelyst::Application *app=nullptr) |
| QStringList | staticMap () const |
| QStringList | staticMap2 () const |
| void | stop () |
| bool | tcpNodelay () const |
| QString | threads () const |
| QStringList | touchReload () const |
| QString | uid () const |
| QString | umask () const |
| bool | upgradeH2c () const |
| bool | usingFrontendProxy () const |
| int | websocketMaxSize () const |
| Public Member Functions inherited from QObject | |
| QObject (QObject *parent) | |
| QBindable< QString > | bindableObjectName () |
| bool | blockSignals (bool block) |
| const QObjectList & | children () const const |
| QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const |
| void | deleteLater () |
| void | destroyed (QObject *obj) |
| bool | disconnect (const char *signal, const QObject *receiver, const char *method) const const |
| bool | disconnect (const QObject *receiver, const char *method) const const |
| void | dumpObjectInfo () const const |
| void | dumpObjectTree () const const |
| QList< QByteArray > | dynamicPropertyNames () const const |
| virtual bool | event (QEvent *e) |
| virtual bool | eventFilter (QObject *watched, QEvent *event) |
| T | findChild (QAnyStringView name, Qt::FindChildOptions options) const const |
| T | findChild (Qt::FindChildOptions options) const const |
| QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const |
| QList< T > | findChildren (QAnyStringView name, Qt::FindChildOptions options) const const |
| QList< T > | findChildren (Qt::FindChildOptions options) const const |
| bool | inherits (const char *className) const const |
| void | installEventFilter (QObject *filterObj) |
| bool | isQmlExposed () const const |
| bool | isQuickItemType () const const |
| bool | isWidgetType () const const |
| bool | isWindowType () const const |
| void | killTimer (int id) |
| void | killTimer (Qt::TimerId id) |
| virtual const QMetaObject * | metaObject () const const |
| bool | moveToThread (QThread *targetThread) |
| QString | objectName () const const |
| void | objectNameChanged (const QString &objectName) |
| QObject * | parent () const const |
| QVariant | property (const char *name) const const |
| Q_CLASSINFO (Name, Value) | |
| Q_EMIT Q_EMIT | |
| Q_ENUM (...) | |
| Q_ENUM_NS (...) | |
| Q_ENUMS (...) | |
| Q_FLAG (...) | |
| Q_FLAG_NS (...) | |
| Q_FLAGS (...) | |
| Q_GADGET Q_GADGET | |
| Q_GADGET_EXPORT (EXPORT_MACRO) | |
| Q_INTERFACES (...) | |
| Q_INVOKABLE Q_INVOKABLE | |
| Q_MOC_INCLUDE Q_MOC_INCLUDE | |
| Q_NAMESPACE Q_NAMESPACE | |
| Q_NAMESPACE_EXPORT (EXPORT_MACRO) | |
| Q_OBJECT Q_OBJECT | |
| Q_PROPERTY (...) | |
| Q_REVISION Q_REVISION | |
| Q_SET_OBJECT_NAME (Object) | |
| Q_SIGNAL Q_SIGNAL | |
| Q_SIGNALS Q_SIGNALS | |
| Q_SLOT Q_SLOT | |
| Q_SLOTS Q_SLOTS | |
| T | qobject_cast (const QObject *object) |
| T | qobject_cast (QObject *object) |
| QT_NO_CONTEXTLESS_CONNECT QT_NO_CONTEXTLESS_CONNECT | |
| QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT | |
| void | removeEventFilter (QObject *obj) |
| void | setObjectName (const QString &name) |
| void | setObjectName (QAnyStringView name) |
| void | setParent (QObject *parent) |
| bool | setProperty (const char *name, const QVariant &value) |
| bool | setProperty (const char *name, QVariant &&value) |
| bool | signalsBlocked () const const |
| int | startTimer (int interval, Qt::TimerType timerType) |
| int | startTimer (std::chrono::nanoseconds interval, Qt::TimerType timerType) |
| QThread * | thread () const const |
Properties | |
| QString | application |
| bool | auto_reload |
| int | buffer_size |
| QString | chdir |
| QString | chdir2 |
| QString | chown_socket |
| int | cpu_affinity |
| QStringList | fastcgi_socket |
| QString | gid |
| quint32 | http2_header_table_size |
| QStringList | http2_socket |
| QStringList | http_socket |
| bool | https_h2 |
| QStringList | https_socket |
| QStringList | ini |
| QStringList | json |
| bool | lazy |
| int | listen |
| bool | master |
| bool | no_initgroups |
| QString | pidfile |
| QString | pidfile2 |
| qint64 | post_buffering |
| qint64 | post_buffering_bufsize |
| QString | processes |
| bool | reuse_port |
| bool | so_keepalive |
| QString | socket_access |
| int | socket_rcvbuf |
| int | socket_sndbuf |
| int | socket_timeout |
| QStringList | static_map |
| QStringList | static_map2 |
| bool | tcp_nodelay |
| QString | threads |
| QStringList | touch_reload |
| QString | uid |
| QString | umask |
| bool | upgrade_h2c |
| bool | using_frontend_proxy |
| int | websocket_max_size |
| Properties inherited from QObject | |
| objectName | |
Additional Inherited Members | |
| Public Types inherited from QObject | |
| enum | TimerId |
| Static Public Member Functions inherited from QObject | |
| QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
| QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
| QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type) |
| QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) |
| QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, Functor functor) |
| bool | disconnect (const QMetaObject::Connection &connection) |
| bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
| bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
| bool | disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method) |
| QString | tr (const char *sourceText, const char *disambiguation, int n) |
| Public Attributes inherited from QObject | |
| Invalid | |
| typedef | QObjectList |
| Protected Member Functions inherited from QObject | |
| virtual void | childEvent (QChildEvent *event) |
| virtual void | connectNotify (const QMetaMethod &signal) |
| virtual void | customEvent (QEvent *event) |
| virtual void | disconnectNotify (const QMetaMethod &signal) |
| bool | isSignalConnected (const QMetaMethod &signal) const const |
| int | receivers (const char *signal) const const |
| QObject * | sender () const const |
| int | senderSignalIndex () const const |
| virtual void | timerEvent (QTimerEvent *event) |
The Server class implements a web server that can either act on it’s own or behind another server like nginx or Apache. This class is used by cutelystd4-qt6 but can also be integrated into your own application to start() and stop() a Cutelyst server.
All command line options from cutelystd4-qt6 have their counterparts as properties of this class. Using the server section of your application configuration file you can set this properties via configuration file options. Simply use the property names as configuration keys.
The Cutelyst server uses the following logging categories:
|
explicit |
Constructs a new Server object with the given parent.
Definition at line 45 of file server.cpp.
References QObject::QObject(), Server(), QCoreApplication::addLibraryPath(), QObject::connect(), errorOccured(), QObject::parent(), QCoreApplication::setEventDispatcher(), and stopped().
Referenced by Server(), config(), exec(), parseCommandLine(), start(), and stop().
|
virtual |
Destroys the Server object.
Definition at line 89 of file server.cpp.
|
nodiscard |
Definition at line 1065 of file server.cpp.
|
nodiscard |
Definition at line 1358 of file server.cpp.
|
nodiscard |
Definition at line 1401 of file server.cpp.
|
signal |
|
nodiscard |
Definition at line 1120 of file server.cpp.
|
nodiscard |
Definition at line 1250 of file server.cpp.
|
nodiscard |
Definition at line 1582 of file server.cpp.
|
nodiscardnoexcept |
Returns the configuration set by setIni() and setJson().
Definition at line 1661 of file server.cpp.
References Server().
|
nodiscard |
Definition at line 1612 of file server.cpp.
|
signal |
It is emitted once error occurs.
References errorOccured().
Referenced by Server(), errorOccured(), exec(), and start().
| int Server::exec | ( | Cutelyst::Application * | app = nullptr | ) |
This function will start the server.
If an application app is provided, it will ignore the value of setApplication and/or the application configuration key in case ini or json is set, meaning it won’t dynamically load an Application but use this to create new instances (if the app constructor is marked as Q_INVOKABLE and threads settings are greater than 1).
It will return 0 in case of sucess.
Definition at line 677 of file server.cpp.
References Server(), QObject::connect(), Qt::DirectConnection, errorOccured(), QString::fromLatin1(), QThread::idealThreadCount(), QObject::Q_EMIT(), ready(), and QDir::setCurrent().
Referenced by start().
|
nodiscard |
Definition at line 1211 of file server.cpp.
|
nodiscard |
Definition at line 1552 of file server.cpp.
|
nodiscard |
Definition at line 1159 of file server.cpp.
|
nodiscard |
Definition at line 1146 of file server.cpp.
|
nodiscard |
Definition at line 1185 of file server.cpp.
|
nodiscard |
Definition at line 1133 of file server.cpp.
|
nodiscard |
Definition at line 1198 of file server.cpp.
|
nodiscard |
Definition at line 1276 of file server.cpp.
|
nodiscard |
Definition at line 1302 of file server.cpp.
|
nodiscard |
Definition at line 1642 of file server.cpp.
|
nodiscard |
Definition at line 1384 of file server.cpp.
|
nodiscard |
Definition at line 1343 of file server.cpp.
|
nodiscard |
Definition at line 1567 of file server.cpp.
| void Server::parseCommandLine | ( | const QStringList & | args | ) |
Parses args from the command line and sets the Server properties. This will take a list returned by eg. QCoreApplication::arguments().
Definition at line 95 of file server.cpp.
References Server(), QCommandLineParser::addHelpOption(), QCommandLineParser::addOption(), QCommandLineParser::addVersionOption(), application, chdir, chdir2, QCommandLineParser::isSet(), master, QCommandLineParser::process(), processes, QCommandLineParser::setApplicationDescription(), QCommandLineParser::showHelp(), threads, QString::toInt(), QString::toLongLong(), QString::toUInt(), QCommandLineParser::value(), and QCommandLineParser::values().
|
nodiscard |
Definition at line 1509 of file server.cpp.
|
nodiscard |
Definition at line 1522 of file server.cpp.
|
nodiscard |
Definition at line 1414 of file server.cpp.
|
nodiscard |
Definition at line 1431 of file server.cpp.
|
nodiscard |
Definition at line 1104 of file server.cpp.
|
signal |
It is emitted once the server is ready.
References QObject::Q_SIGNALS(), and ready().
|
nodiscard |
Definition at line 1629 of file server.cpp.
| void Server::setApplication | ( | const QString & | application | ) |
Definition at line 1050 of file server.cpp.
| void Server::setAutoReload | ( | bool | enable | ) |
Definition at line 1349 of file server.cpp.
| void Server::setBufferSize | ( | int | size | ) |
Definition at line 1390 of file server.cpp.
| void Server::setChdir | ( | const QString & | chdir | ) |
Definition at line 1113 of file server.cpp.
| void Server::setChdir2 | ( | const QString & | chdir2 | ) |
Definition at line 1243 of file server.cpp.
| void Server::setChownSocket | ( | const QString & | chownSocket | ) |
Definition at line 1573 of file server.cpp.
| void Server::setCpuAffinity | ( | int | value | ) |
Definition at line 1603 of file server.cpp.
| void Server::setFastcgiSocket | ( | const QStringList & | fastcgiSocket | ) |
Definition at line 1204 of file server.cpp.
| void Server::setGid | ( | const QString & | gid | ) |
Definition at line 1543 of file server.cpp.
| void Server::setHttp2HeaderTableSize | ( | quint32 | headerTableSize | ) |
Definition at line 1152 of file server.cpp.
| void Server::setHttp2Socket | ( | const QStringList & | http2Socket | ) |
Definition at line 1139 of file server.cpp.
| void Server::setHttpsH2 | ( | bool | enable | ) |
Definition at line 1178 of file server.cpp.
| void Server::setHttpSocket | ( | const QStringList & | httpSocket | ) |
Definition at line 1126 of file server.cpp.
| void Server::setHttpsSocket | ( | const QStringList & | httpsSocket | ) |
Definition at line 1191 of file server.cpp.
| void Server::setIni | ( | const QStringList & | files | ) |
Definition at line 1256 of file server.cpp.
| void Server::setJson | ( | const QStringList & | files | ) |
Definition at line 1282 of file server.cpp.
| void Server::setLazy | ( | bool | enable | ) |
Definition at line 1635 of file server.cpp.
| void Server::setListenQueue | ( | int | size | ) |
Definition at line 1377 of file server.cpp.
| void Server::setMaster | ( | bool | enable | ) |
Definition at line 1334 of file server.cpp.
| void Server::setNoInitgroups | ( | bool | enable | ) |
Definition at line 1558 of file server.cpp.
| void Server::setPidfile | ( | const QString & | file | ) |
Definition at line 1502 of file server.cpp.
| void Server::setPidfile2 | ( | const QString & | file | ) |
Definition at line 1515 of file server.cpp.
| void Server::setPostBuffering | ( | qint64 | size | ) |
Definition at line 1407 of file server.cpp.
| void Server::setPostBufferingBufsize | ( | qint64 | size | ) |
Definition at line 1420 of file server.cpp.
| void Server::setProcesses | ( | const QString & | process | ) |
Definition at line 1091 of file server.cpp.
| void Server::setReusePort | ( | bool | enable | ) |
Definition at line 1618 of file server.cpp.
| void Server::setSocketAccess | ( | const QString & | socketAccess | ) |
Definition at line 1217 of file server.cpp.
| void Server::setSocketRcvbuf | ( | int | value | ) |
Definition at line 1476 of file server.cpp.
| void Server::setSocketSndbuf | ( | int | value | ) |
Definition at line 1463 of file server.cpp.
| void Server::setSocketTimeout | ( | int | timeout | ) |
Definition at line 1230 of file server.cpp.
| void Server::setSoKeepalive | ( | bool | enable | ) |
Definition at line 1450 of file server.cpp.
| void Server::setStaticMap | ( | const QStringList & | staticMap | ) |
Definition at line 1308 of file server.cpp.
| void Server::setStaticMap2 | ( | const QStringList & | staticMap | ) |
Definition at line 1321 of file server.cpp.
| void Server::setTcpNodelay | ( | bool | enable | ) |
Definition at line 1437 of file server.cpp.
| void Server::setThreads | ( | const QString & | threads | ) |
Definition at line 1071 of file server.cpp.
| void Server::setTouchReload | ( | const QStringList & | files | ) |
Definition at line 1364 of file server.cpp.
| void Server::setUid | ( | const QString & | uid | ) |
Definition at line 1528 of file server.cpp.
| void Server::setUmask | ( | const QString & | value | ) |
Definition at line 1588 of file server.cpp.
| void Server::setUpgradeH2c | ( | bool | enable | ) |
Definition at line 1165 of file server.cpp.
| void Server::setUsingFrontendProxy | ( | bool | enable | ) |
Definition at line 1648 of file server.cpp.
| void Server::setWebsocketMaxSize | ( | int | value | ) |
Definition at line 1489 of file server.cpp.
|
nodiscard |
Definition at line 1224 of file server.cpp.
|
nodiscard |
Definition at line 1483 of file server.cpp.
|
nodiscard |
Definition at line 1470 of file server.cpp.
|
nodiscard |
Definition at line 1237 of file server.cpp.
|
nodiscard |
Definition at line 1457 of file server.cpp.
| bool Server::start | ( | Cutelyst::Application * | app = nullptr | ) |
This function will start the server in user application mode.
Use this when you would like to embed the server in an application that is able to start/stop the server at will, for example with a push button.
This method does not support forking which includes master, lazy or processes properties.
New application instances will be created if the app constructor is marked as Q_INVOKABLE and threads settings are greater than 1.
Definition at line 831 of file server.cpp.
References Server(), errorOccured(), exec(), and QObject::Q_EMIT().
|
nodiscard |
Definition at line 1315 of file server.cpp.
|
nodiscard |
Definition at line 1328 of file server.cpp.
| void Server::stop | ( | ) |
Terminates the server execution, when started with start(), it does nothing when started by exec().
Definition at line 858 of file server.cpp.
References Server(), and QObject::Q_EMIT().
|
signal |
|
nodiscard |
Definition at line 1444 of file server.cpp.
|
nodiscard |
Definition at line 1082 of file server.cpp.
|
nodiscard |
Definition at line 1371 of file server.cpp.
|
nodiscard |
Definition at line 1537 of file server.cpp.
|
nodiscard |
Definition at line 1597 of file server.cpp.
|
nodiscard |
Definition at line 1172 of file server.cpp.
|
nodiscard |
Definition at line 1655 of file server.cpp.
|
nodiscard |
Definition at line 1496 of file server.cpp.
|
readwrite |
Defines application file path to be loaded, an alternative is to provide the Cutelyst::Application pointer to exec().
Definition at line 134 of file server.h.
Referenced by parseCommandLine().
|
readwrite |
|
readwrite |
|
readwrite |
Defines directory to change into before application loading.
Definition at line 167 of file server.h.
Referenced by parseCommandLine().
|
readwrite |
Defines directory to change into after application loading.
Definition at line 250 of file server.h.
Referenced by parseCommandLine().
|
readwrite |
|
readwrite |
|
readwrite |
|
readwrite |
|
readwrite |
|
readwrite |
|
readwrite |
|
readwrite |
|
readwrite |
|
readwrite |
Load config from INI files that will be read by QSettings. When loading multiple files, content will be merged and same keys in the sections will be overwritten by content from later files.
|
readwrite |
Load config from JSON files containing a JSON object. When loading multiple files, content will be merged and same keys int the sections will be overwritten by content from later files.
This is only tested for one single root object with flat child objects as config sections.
|
readwrite |
Defines is the Application should be lazy loaded.
|
readwrite |
|
readwrite |
Defines if a master process should be created to watch for it’s child processes.
Definition at line 341 of file server.h.
Referenced by parseCommandLine().
|
readwrite |
|
readwrite |
|
readwrite |
|
readwrite |
|
readwrite |
|
readwrite |
Defines the number of processes to use, if set to "auto" the ideal processes count is used.
Definition at line 159 of file server.h.
Referenced by parseCommandLine().
|
readwrite |
|
readwrite |
|
readwrite |
|
readwrite |
|
readwrite |
|
readwrite |
|
readwrite |
Defines a list of mountpoint to local path mappings to serve static files. Entries have to be in the form “/mountpoint=/path/to/local/dir”. If there is then a request for eg. /mountpoint/css/style.css, the Server will remove the mountpoint from the request path and will append the rest to the local path to try to find the requested file, like /path/to/local/dir/css/style.css.
Added mappings are automatically sorted by the string length of the mounpoint part from short to long and will be compared to the request path in that order.
|
readwrite |
Defines a list of mountpoint to local path mappings to serve static files. Entries have to be in the form “/mountpoint=/path/to/local/dir”. If there ist then a request for eg. /mountpoint/js/script.js, the Server will completely append the request path to the local path to try to find the requested file, like /path/to/local/dir/mountpoint/js/script.js.
Added mappings are automatically sorted by the string length of the mounpoint part from short to long and will be compared to the request path in that order.
|
readwrite |
|
readwrite |
Defines the number of threads to use, if set to "auto" the ideal thread count is used.
A new thread is only created when > "2" or if "auto" reports more than 1 core, when the number of threads is 2 or more a new thread is not created for the worker 0, it's this way to save allocating a new Application as we already have our current thread.
If it's desired to not have the Server running on the GUI (or current) thread for example, the Server must be moved to a new thread manually.
Definition at line 150 of file server.h.
Referenced by parseCommandLine().
|
readwrite |
|
readwrite |
|
readwrite |
|
readwrite |
|
readwrite |
Defines if a reverse proxy operates in front of this application server. If enabled, parses the HTTP headers X-Forwarded-For, X-Forwarded-Host and X-Forwarded-Proto and uses this info to update Cutelyst::EngineRequest.