10 #include "request_p.h"
11 #include "application.h"
12 #include "response_p.h"
13 #include "context_p.h"
20 #include <QJsonDocument>
45 : d_ptr(new EnginePrivate)
101 if (thread() != QThread::currentThread()) {
102 qCCritical(CUTELYST_ENGINE) <<
"Cannot init application on a different thread";
106 if (!d->app->setup(
this)) {
107 qCCritical(CUTELYST_ENGINE) <<
"Failed to setup application";
119 qCCritical(CUTELYST_ENGINE) <<
"Failed to postForkApplication on a null application";
123 QThread::currentThread()->setObjectName(QString::number(d->workerCore));
125 return d->app->enginePostFork();
130 return quint64(QDateTime::currentMSecsSinceEpoch() * 1000);
138 ret =
"HTTP/1.1 200 OK";
140 case Response::Found:
141 ret =
"HTTP/1.1 302 Found";
143 case Response::NotFound:
144 ret =
"HTTP/1.1 404 Not Found";
146 case Response::InternalServerError:
147 ret =
"HTTP/1.1 500 Internal Server Error";
149 case Response::MovedPermanently:
150 ret =
"HTTP/1.1 301 Moved Permanently";
152 case Response::NotModified:
153 ret =
"HTTP/1.1 304 Not Modified";
155 case Response::SeeOther:
156 ret =
"HTTP/1.1 303 See Other";
158 case Response::Forbidden:
159 ret =
"HTTP/1.1 403 Forbidden";
161 case Response::TemporaryRedirect:
162 ret =
"HTTP/1.1 307 Temporary Redirect";
164 case Response::Unauthorized:
165 ret =
"HTTP/1.1 401 Unauthorized";
167 case Response::BadRequest:
168 ret =
"HTTP/1.1 400 Bad Request";
170 case Response::MethodNotAllowed:
171 ret =
"HTTP/1.1 405 Method Not Allowed";
173 case Response::RequestTimeout:
174 ret =
"HTTP/1.1 408 Request Timeout";
176 case Response::Continue:
177 ret =
"HTTP/1.1 100 Continue";
179 case Response::SwitchingProtocols:
180 ret =
"HTTP/1.1 101 Switching Protocols";
182 case Response::Created:
183 ret =
"HTTP/1.1 201 Created";
185 case Response::Accepted:
186 ret =
"HTTP/1.1 202 Accepted";
188 case Response::NonAuthoritativeInformation:
189 ret =
"HTTP/1.1 203 Non-Authoritative Information";
191 case Response::NoContent:
192 ret =
"HTTP/1.1 204 No Content";
194 case Response::ResetContent:
195 ret =
"HTTP/1.1 205 Reset Content";
197 case Response::PartialContent:
198 ret =
"HTTP/1.1 206 Partial Content";
200 case Response::MultipleChoices:
201 ret =
"HTTP/1.1 300 Multiple Choices";
203 case Response::UseProxy:
204 ret =
"HTTP/1.1 305 Use Proxy";
206 case Response::PaymentRequired:
207 ret =
"HTTP/1.1 402 Payment Required";
209 case Response::NotAcceptable:
210 ret =
"HTTP/1.1 406 Not Acceptable";
212 case Response::ProxyAuthenticationRequired:
213 ret =
"HTTP/1.1 407 Proxy Authentication Required";
215 case Response::Conflict:
216 ret =
"HTTP/1.1 409 Conflict";
219 ret =
"HTTP/1.1 410 Gone";
221 case Response::LengthRequired:
222 ret =
"HTTP/1.1 411 Length Required";
224 case Response::PreconditionFailed:
225 ret =
"HTTP/1.1 412 Precondition Failed";
227 case Response::RequestEntityTooLarge:
228 ret =
"HTTP/1.1 413 Request Entity Too Large";
230 case Response::RequestURITooLong:
231 ret =
"HTTP/1.1 414 Request-URI Too Long";
233 case Response::UnsupportedMediaType:
234 ret =
"HTTP/1.1 415 Unsupported Media Type";
236 case Response::RequestedRangeNotSatisfiable:
237 ret =
"HTTP/1.1 416 Requested Range Not Satisfiable";
239 case Response::ExpectationFailed:
240 ret =
"HTTP/1.1 417 Expectation Failed";
242 case Response::NotImplemented:
243 ret =
"HTTP/1.1 501 Not Implemented";
245 case Response::BadGateway:
246 ret =
"HTTP/1.1 502 Bad Gateway";
248 case Response::ServiceUnavailable:
249 ret =
"HTTP/1.1 503 Service Unavailable";
251 case Response::MultiStatus:
252 ret =
"HTTP/1.1 207 Multi-Status";
254 case Response::GatewayTimeout:
255 ret =
"HTTP/1.1 504 Gateway Timeout";
257 case Response::HTTPVersionNotSupported:
258 ret =
"HTTP/1.1 505 HTTP Version Not Supported";
260 case Response::BandwidthLimitExceeded:
261 ret =
"HTTP/1.1 509 Bandwidth Limit Exceeded";
264 ret = QByteArrayLiteral(
"HTTP/1.1 ").append(QByteArray::number(status)).constData();
269 *len = int(strlen(ret));
277 return d->app->defaultHeaders();
283 d->app->handleRequest(request);
295 return d->config.value(entity).toMap();
307 QSettings settings(filename, QSettings::IniFormat);
308 if (settings.status() != QSettings::NoError) {
309 qCWarning(CUTELYST_ENGINE) <<
"Failed to load INI file:" << settings.status();
313 const auto groups = settings.childGroups();
314 for (
const QString &group : groups) {
315 QVariantMap configGroup;
316 settings.beginGroup(group);
317 const auto child = settings.childKeys();
318 for (
const QString &key : child) {
319 configGroup.insert(key, settings.value(key));
322 ret.insert(group, configGroup);
331 QFile file(filename);
332 if (!file.open(QIODevice::ReadOnly)) {
335 QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
337 ret = doc.toVariant().toMap();
342 #include "moc_engine.cpp"
The Cutelyst Application.
static QVariantMap loadJsonConfig(const QString &filename)
Engine(Application *app, int workerCore, const QVariantMap &opts)
bool initApplication()
initApplication
int workerCore() const
Each worker process migth have a number of worker cores (threads), a single process with two worker t...
bool postForkApplication()
postForkApplication
void setConfig(const QVariantMap &config)
void processRequestAsync(Cutelyst::EngineRequest *request)
static const char * httpStatusMessage(quint16 status, int *len=nullptr)
void processRequest(EngineRequest *request)
QVariantMap config(const QString &entity) const
user configuration for the application
Application * app() const
application
Headers & defaultHeaders()
static QVariantMap loadIniConfig(const QString &filename)
The Cutelyst namespace holds all public Cutelyst API.