-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathKStaticFileCache.h
More file actions
39 lines (29 loc) · 866 Bytes
/
Copy pathKStaticFileCache.h
File metadata and controls
39 lines (29 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#pragma once
#include "webserver/utils/Knoncopyable.h"
#include <memory>
#include <shared_mutex>
#include <string>
#include <unordered_map>
namespace kback {
class StaticFileCache : noncopyable {
public:
struct Entry {
Entry(std::string fullPath, std::string contentType, size_t fileSize,
int fileFd);
~Entry();
std::string fullPath;
std::string contentType;
size_t fileSize;
int fileFd;
};
StaticFileCache();
void setRoot(std::string root);
std::shared_ptr<const Entry> find(const std::string &requestPath);
private:
std::string normalizeRequestPath(const std::string &requestPath) const;
std::shared_ptr<Entry> loadEntry(const std::string &normalizedPath);
std::string root_;
mutable std::shared_mutex mutex_;
std::unordered_map<std::string, std::shared_ptr<Entry>> entries_;
};
} // namespace kback