5 #include "serverengine.h" 8 #include "localserver.h" 10 #include "protocolfastcgi.h" 11 #include "protocolhttp.h" 12 #include "protocolhttp2.h" 13 #include "protocolwebsocket.h" 16 #include "staticmap.h" 17 #include "tcpserver.h" 18 #include "tcpserverbalancer.h" 19 #include "tcpsslserver.h" 22 # include "unixfork.h" 25 #include <Cutelyst/Application> 26 #include <Cutelyst/Context> 27 #include <Cutelyst/Request> 28 #include <Cutelyst/Response> 32 #include <QCoreApplication> 33 #include <QLoggingCategory> 35 Q_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(
76 ServerEngine::~ServerEngine()
88 void ServerEngine::setServers(
const std::vector<QObject *> &servers)
90 for (
QObject *server : servers) {
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()) {
113 sslServer->setHttp2Protocol(getProtoHttp2());
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());
144 void 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"));
170 Protocol *ServerEngine::getProtoHttp()
173 if (m_wsgi->upgradeH2c()) {
174 m_protoHttp =
new ProtocolHttp(m_wsgi, getProtoHttp2());
190 Protocol *ServerEngine::getProtoFastCgi()
207 void 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" QString toString(qlonglong i) const const
virtual bool init() override
bool postForkApplication()
bool isEmpty() const const
The Cutelyst namespace holds all public Cutelyst API.
QByteArray toLatin1() const const
virtual int workerId() const override
The Cutelyst application.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
T qobject_cast(QObject *object)
QDateTime currentDateTimeUtc()