aboutsummaryrefslogtreecommitdiff
path: root/src/content/static/Static.cpp
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2021-10-04 16:56:02 +0200
committerToni Uhlig <matzeton@googlemail.com>2021-10-04 16:56:02 +0200
commitf0f4b8a4d139a855ad15f9d79190edf6320eba51 (patch)
tree4ba361738f08bf44769e3454832d765ba8d7f2c1 /src/content/static/Static.cpp
parent5ff3d7a51be30a0052b12f9330fdf54f3c104739 (diff)
Static file cache content module.
* remove EVHTTP headers * magic/mime type support for virtual Filesystem Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'src/content/static/Static.cpp')
-rw-r--r--src/content/static/Static.cpp31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/content/static/Static.cpp b/src/content/static/Static.cpp
index 5e38b76..b9977a9 100644
--- a/src/content/static/Static.cpp
+++ b/src/content/static/Static.cpp
@@ -1,20 +1,18 @@
#include "Static.hpp"
-Static::Static(std::string uriBasePath, std::string staticFilesPath)
- : Content(), m_UriBasePath(uriBasePath), m_MainTemplatePath(""), m_StaticFilesPath(staticFilesPath)
+Static::Static(std::string uriBasePath, std::shared_ptr<Filesystem> const & fs)
+ : Content(), m_UriBasePath(uriBasePath), m_MainTemplatePath(""), m_StaticFiles(fs)
{
+ for (auto const & file : fs->GetFiles())
+ {
+ m_Redirections.push_back(uriBasePath + "/" + file.first);
+ m_UriToFsMapping[uriBasePath + "/" + file.first] = file.first;
+ }
}
bool Static::Init()
{
- std::cout << "Static files path: " << m_StaticFilesPath << std::endl;
-
- std::vector<std::string> extensions = {"json"};
-
- if (m_StaticFiles.Scan(m_StaticFilesPath, extensions, false) == false)
- {
- return false;
- }
+ std::cout << "Static files: " << m_StaticFiles->GetFiles().size() << std::endl;
return true;
}
@@ -26,11 +24,18 @@ void Static::Shutdown()
bool Static::Render(RequestResponse & rr, RenderData & rd, std::string & out)
{
- (void)rr;
(void)rd;
- (void)out;
- rd["blah"] = "Yooooh!";
+ rr.UseOutputHeader();
+ auto & files = m_StaticFiles->GetFiles();
+ auto const & path = std::string(rr.GetUriPath());
+
+ if (rr.AddOutputHeader("Content-Type", files[m_UriToFsMapping[path]].mime) == false)
+ {
+ return false;
+ }
+
+ out = std::string(files[m_UriToFsMapping[path]].data.begin(), files[m_UriToFsMapping[path]].data.end());
return true;
}