5#include "serverengine.h"
8#include "localserver.h"
10#include "protocolfastcgi.h"
11#include "protocolhttp.h"
12#include "protocolhttp2.h"
13#include "protocolwebsocket.h"
18#include "tcpserverbalancer.h"
19#include "tcpsslserver.h"
25#include <Cutelyst/Application>
26#include <Cutelyst/Context>
27#include <Cutelyst/Request>
28#include <Cutelyst/Response>
32#include <QCoreApplication>
33#include <QLoggingCategory>
35Q_LOGGING_CATEGORY(C_SERVER_ENGINE,
"cutelyst.server.engine", QtWarningMsg)
43 const QVariantMap &opts,
45 :
Engine(localApp, workerCore, opts)
48 m_lastDate = dateHeader();
49 m_lastDateTimer.start();
51 if (m_wsgi->socketTimeout()) {
52 m_socketTimeout =
new QTimer(
this);
53 m_socketTimeout->setObjectName(QStringLiteral(
"Cutelyst::socketTimeout"));
54 m_socketTimeout->setInterval(std::chrono::seconds{m_wsgi->socketTimeout()});
57 connect(
this, &ServerEngine::shutdown, app(), [
this] { Q_EMIT app() -> shuttingDown(app()); });
60 const QStringList staticMap2 = m_wsgi->staticMap2();
61 if (!staticMap.isEmpty() || !staticMap2.
isEmpty()) {
62 auto staticMapPlugin =
new StaticMap(app());
64 for (
const QString &part : staticMap) {
65 staticMapPlugin->addStaticMap(
69 for (
const QString &part : staticMap2) {
70 staticMapPlugin->addStaticMap(
76ServerEngine::~ServerEngine()
88void ServerEngine::setServers(
const std::vector<QObject *> &servers)
90 for (
QObject *server : servers) {
91 auto balancer = qobject_cast<TcpServerBalancer *>(server);
93 TcpServer *server = balancer->createServer(
this);
96 if (m_socketTimeout) {
98 m_socketTimeout, &
QTimer::timeout, server, &TcpServer::timeoutConnections);
101 if (server->protocol()->type() == Protocol::Type::Http11) {
102 server->setProtocol(getProtoHttp());
103 }
else if (server->protocol()->type() == Protocol::Type::Http2) {
104 server->setProtocol(getProtoHttp2());
105 }
else if (server->protocol()->type() == Protocol::Type::FastCGI1) {
106 server->setProtocol(getProtoFastCgi());
110 if (m_wsgi->httpsH2()) {
111 auto sslServer = qobject_cast<TcpSslServer *>(server);
113 sslServer->setHttp2Protocol(getProtoHttp2());
120 auto localServer = qobject_cast<LocalServer *>(server);
122 LocalServer *server = localServer->createServer(
this);
125 if (m_socketTimeout) {
129 &LocalServer::timeoutConnections);
132 if (server->protocol()->type() == Protocol::Type::Http11) {
133 server->setProtocol(getProtoHttp());
134 }
else if (server->protocol()->type() == Protocol::Type::Http2) {
135 server->setProtocol(getProtoHttp2());
136 }
else if (server->protocol()->type() == Protocol::Type::FastCGI1) {
137 server->setProtocol(getProtoFastCgi());
144void ServerEngine::postFork(
int workerId)
155 std::cerr <<
"Application failed to post fork, cheaping worker: " <<
workerId
166 QStringLiteral(
"ddd, dd MMM yyyy hh:mm:ss 'GMT"));
170Protocol *ServerEngine::getProtoHttp()
173 if (m_wsgi->upgradeH2c()) {
174 m_protoHttp =
new ProtocolHttp(m_wsgi, getProtoHttp2());
190Protocol *ServerEngine::getProtoFastCgi()
207void ServerEngine::handleSocketShutdown(
Socket *socket)
209 if (socket->processing == 0) {
210 socket->connectionClose();
211 }
else if (socket->proto->type() == Protocol::Type::Http11Websocket) {
213 req->webSocketClose(Response::CloseCode::CloseCodeGoingAway, {});
215 socket->protoData->headerConnection = ProtocolData::HeaderConnection::Close;
219#include "moc_serverengine.cpp"
The Cutelyst application.
bool postForkApplication()
virtual int workerId() const override
virtual bool init() override
The Cutelyst namespace holds all public Cutelyst API.
QDateTime currentDateTimeUtc()
bool isEmpty() const const
QString toString(QDate date, QLocale::FormatType format) const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QByteArray toLatin1() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)