Intial somewhat working version
This commit is contained in:
29
src/FileUtil.cpp
Normal file
29
src/FileUtil.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "FileUtil.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
std::optional<std::string> readTextFile(const std::filesystem::path& path)
|
||||
{
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
if (!file)
|
||||
return std::nullopt;
|
||||
|
||||
std::ostringstream buffer;
|
||||
buffer << file.rdbuf();
|
||||
return buffer.str();
|
||||
}
|
||||
|
||||
std::string contentTypeForPath(const std::filesystem::path& path)
|
||||
{
|
||||
const auto ext = path.extension().string();
|
||||
if (ext == ".html")
|
||||
return "text/html; charset=utf-8";
|
||||
if (ext == ".css")
|
||||
return "text/css; charset=utf-8";
|
||||
if (ext == ".js")
|
||||
return "application/javascript; charset=utf-8";
|
||||
if (ext == ".json")
|
||||
return "application/json; charset=utf-8";
|
||||
return "application/octet-stream";
|
||||
}
|
||||
Reference in New Issue
Block a user