11#include <promeki/config.h>
12#if PROMEKI_ENABLE_HTTP
19PROMEKI_NAMESPACE_BEGIN
67class HttpFileHandler :
public HttpHandler {
68 PROMEKI_SHARED_DERIVED(HttpFileHandler)
71 static const String DefaultIndexFile;
74 static constexpr int64_t StreamChunkBytes = 64 * 1024;
83 explicit HttpFileHandler(
const Dir &root);
86 explicit HttpFileHandler(
const String &rootPath);
89 const Dir &root()
const {
return _root; }
100 void setPathParamName(
const String &name) { _pathParam = name; }
109 void setIndexFile(
const String &name) { _indexFile = name; }
119 void addMimeType(
const String &ext,
const String &mime);
129 void setListDirectories(
bool enable) { _listDirs = enable; }
140 String resolveRequestPath(
const HttpRequest &request)
const;
143 String mimeType(
const String &filePath)
const;
146 void serve(
const HttpRequest &request, HttpResponse &response)
override;
150 String _pathParam =
"path";
151 String _indexFile = DefaultIndexFile;
152 bool _listDirs =
false;
153 HashMap<String, String> _extraMime;
155 static String etagFor(int64_t size, int64_t mtimeEpoch);
156 static String httpDateFor(int64_t mtimeEpoch);
157 static bool isPathSafe(
const String &relPath);
159 bool serveRange(
const HttpRequest &request, HttpResponse &response,
const String &fullPath,
160 int64_t fileSize,
const String &mime);