9#include <Cutelyst/Application>
10#include <Cutelyst/Request>
11#include <Cutelyst/Response>
15#include <QLoggingCategory>
17Q_LOGGING_CATEGORY(C_SERVER_SM,
"cutelyst.server.staticmap", QtWarningMsg)
33void StaticMap::addStaticMap(
const QString &mountPoint,
const QString &path,
bool append)
35 QString mp = mountPoint;
36 if (!mp.startsWith(u
'/')) {
40 qCInfo(C_SERVER_SM) <<
"added mapping for" << mp <<
"=>" << path;
42 m_staticMaps.push_back({mp, path, append});
43 std::sort(m_staticMaps.begin(),
46 return a.mountPoint.size() < b.mountPoint.size();
56 const QString path = c->
req()->path();
58 if (path.startsWith(mp.mountPoint)) {
59 if (tryToServeFile(c, mp, path)) {
69 QString localPath = path;
71 localPath = path.mid(mp.mountPoint.size());
73 while (localPath.startsWith(u
'/')) {
74 localPath.remove(0, 1);
78 QString absFilePath = dir.absoluteFilePath(localPath);
79 if (!QFile::exists(absFilePath)) {
83 return serveFile(c, absFilePath);
89 const QDateTime currentDateTime = QFileInfo(filename).lastModified();
95 auto file =
new QFile(filename);
96 if (file->open(QFile::ReadOnly)) {
97 qCDebug(C_SERVER_SM) <<
"Serving" << filename;
104 QMimeType mimeType = m_db.mimeTypeForFile(filename, QMimeDatabase::MatchExtension);
105 if (mimeType.isValid()) {
111 headers.
setHeader(
"Cache-Control"_qba,
"public"_qba);
116 qCWarning(C_SERVER_SM) <<
"Could not serve" << filename << file->errorString();
121#include "moc_staticmap.cpp"
The Cutelyst application.
void beforePrepareAction(Cutelyst::Context *c, bool *skipMethod)
Response * response() const noexcept
Base class for Cutelyst Plugins.
Headers headers() const noexcept
void setStatus(quint16 status) noexcept
virtual bool setup(Cutelyst::Application *app) override
The Cutelyst namespace holds all public Cutelyst API.