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)
26 d->includePaths.append(parent->config(
QLatin1String(
"root")).toString());
37 d->includePaths.clear();
38 for (
const QString &path : paths) {
39 d->includePaths.append(
QDir(path));
52 d->serveDirsOnly = dirsOnly;
61void StaticSimple::beforePrepareAction(
Context *c,
bool *skipMethod)
73 for (
const QString &dir : d->dirs) {
75 if (!locateStaticFile(c, path)) {
87 if (d->serveDirsOnly) {
92 if (match.
hasMatch() && locateStaticFile(c, path)) {
97bool StaticSimple::locateStaticFile(
Context *c,
const QString &relPath)
101 for (
const QDir &includePath : d->includePaths) {
102 QString path = includePath.absoluteFilePath(relPath);
104 if (fileInfo.exists()) {
106 const QDateTime currentDateTime = fileInfo.lastModified();
116 qCDebug(C_STATICSIMPLE) <<
"Serving" << path;
131 headers.
setHeader(
"Cache-Control"_qba,
"public"_qba);
136 qCWarning(C_STATICSIMPLE) <<
"Could not serve" << path << file->
errorString();
141 qCWarning(C_STATICSIMPLE) <<
"File not found" << relPath;
145#include "moc_staticsimple.cpp"
The Cutelyst application.
void beforePrepareAction(Cutelyst::Context *c, bool *skipMethod)
Response * res() const noexcept
Response * response() const noexcept
Base class for Cutelyst Plugins.
Headers headers() const noexcept
void setContentType(const QByteArray &type)
void setStatus(quint16 status) noexcept
void setBody(QIODevice *body)
Headers & headers() noexcept
Serve static files directly from your application.
void setServeDirsOnly(bool dirsOnly)
void setDirs(const QStringList &dirs)
virtual bool setup(Application *app) override
void setIncludePaths(const QStringList &paths)
virtual ~StaticSimple() override
The Cutelyst namespace holds all public Cutelyst API.
bool open(FILE *fh, QIODeviceBase::OpenMode mode, QFileDevice::FileHandleFlags handleFlags)
QString errorString() const const
QMimeType mimeTypeForFile(const QFileInfo &fileInfo, QMimeDatabase::MatchMode mode) const const
bool isValid() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QRegularExpressionMatch match(QStringView subjectView, qsizetype offset, QRegularExpression::MatchType matchType, QRegularExpression::MatchOptions matchOptions) const const
bool hasMatch() const const
QString mid(qsizetype position, qsizetype n) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QByteArray toUtf8() const const