5#include "application.h"
9#include "staticsimple_p.h"
14#include <QLoggingCategory>
15#include <QMimeDatabase>
19Q_LOGGING_CATEGORY(C_STATICSIMPLE,
"cutelyst.plugin.staticsimple", QtWarningMsg)
23 , d_ptr(new StaticSimplePrivate)
29StaticSimple::~StaticSimple()
37 d->includePaths.clear();
38 for (
const QString &path : paths) {
39 d->includePaths.append(
QDir(path));
55void StaticSimple::beforePrepareAction(
Context *c,
bool *skipMethod)
63 const QString path = c->req()->path();
66 for (
const QString &dir : d->dirs) {
68 if (!locateStaticFile(c, path)) {
72 res->
setBody(QStringLiteral(
"File not found: ") + path);
80 QRegularExpressionMatch match = re.
match(path);
81 if (match.
hasMatch() && locateStaticFile(c, path)) {
86bool StaticSimple::locateStaticFile(
Context *c,
const QString &relPath)
90 for (
const QDir &includePath : d->includePaths) {
92 QFileInfo fileInfo(path);
93 if (fileInfo.exists()) {
94 Response *res = c->
res();
95 const QDateTime currentDateTime = fileInfo.lastModified();
101 QFile *file =
new QFile(path);
103 qCDebug(C_STATICSIMPLE) <<
"Serving" << path;
104 Headers &headers = res->
headers();
109 static QMimeDatabase db;
119 headers.
setHeader(QStringLiteral(
"CACHE_CONTROL"), QStringLiteral(
"public"));
124 qCWarning(C_STATICSIMPLE) <<
"Could not serve" << path << file->
errorString();
129 qCWarning(C_STATICSIMPLE) <<
"File not found" << relPath;
133#include "moc_staticsimple.cpp"
The Cutelyst Application.
void beforePrepareAction(Cutelyst::Context *c, bool *skipMethod)
Response * res() const noexcept
Response * response() const noexcept
Plugin(Application *parent)
Headers headers() const noexcept
Headers & headers() noexcept
void setStatus(quint16 status) noexcept
void setBody(QIODevice *body)
void setContentType(const QString &type)
void setDirs(const QStringList &dirs)
virtual bool setup(Application *app) override
StaticSimple(Application *parent)
void setIncludePaths(const QStringList &paths)
The Cutelyst namespace holds all public Cutelyst API.
QString absoluteFilePath(const QString &fileName) const const
virtual bool open(OpenMode mode) override
virtual qint64 size() const const override
QString errorString() const const
QMimeType mimeTypeForFile(const QString &fileName, MatchMode mode) const const
bool isValid() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
QRegularExpressionMatch match(const QString &subject, int offset, MatchType matchType, MatchOptions matchOptions) const const
bool hasMatch() const const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const