5 #include "application.h" 9 #include "staticsimple_p.h" 14 #include <QLoggingCategory> 15 #include <QMimeDatabase> 20 Q_LOGGING_CATEGORY(C_STATICSIMPLE,
"cutelyst.plugin.staticsimple", QtWarningMsg)
24 , d_ptr(new StaticSimplePrivate)
27 d->includePaths.append(parent->config(
QLatin1String(
"root")).toString());
38 d->includePaths.clear();
39 for (
const QString &path : paths) {
40 d->includePaths.append(
QDir(path));
53 d->serveDirsOnly = dirsOnly;
62 void StaticSimple::beforePrepareAction(
Context *c,
bool *skipMethod)
74 for (
const QString &dir : d->dirs) {
76 if (!locateStaticFile(c, path)) {
88 if (d->serveDirsOnly) {
93 if (match.
hasMatch() && locateStaticFile(c, path)) {
98 bool StaticSimple::locateStaticFile(
Context *c,
const QString &relPath)
102 for (
const QDir &includePath : d->includePaths) {
105 if (fileInfo.exists()) {
107 const QDateTime currentDateTime = fileInfo.lastModified();
117 qCDebug(C_STATICSIMPLE) <<
"Serving" << path;
132 headers.
setHeader(
"Cache-Control"_ba,
"public"_ba);
137 qCWarning(C_STATICSIMPLE) <<
"Could not serve" << path << file->
errorString();
142 qCWarning(C_STATICSIMPLE) <<
"File not found" << relPath;
146 #include "moc_staticsimple.cpp" void setDirs(const QStringList &dirs)
Headers & headers() noexcept
QString errorString() const const
Response * res() const noexcept
virtual ~StaticSimple() override
void setContentType(const QByteArray &type)
Headers headers() const noexcept
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
void beforePrepareAction(Cutelyst::Context *c, bool *skipMethod)
Serve static files directly from your application.
virtual bool setup(Application *app) override
bool hasMatch() const const
The Cutelyst namespace holds all public Cutelyst API.
QMimeType mimeTypeForFile(const QFileInfo &fileInfo, MatchMode mode) const const
bool isValid() const const
void setIncludePaths(const QStringList &paths)
QString mid(qsizetype position, qsizetype n) const const
QRegularExpressionMatch match(QStringView subjectView, qsizetype offset, MatchType matchType, MatchOptions matchOptions) const const
QString absoluteFilePath(const QString &fileName) const const
bool open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags)
void setServeDirsOnly(bool dirsOnly)
Base class for Cutelyst Plugins.
The Cutelyst application.
void setBody(QIODevice *body)
Response * response() const noexcept
void setStatus(quint16 status) noexcept
QByteArray toUtf8() const const