-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhandler.hpp
53 lines (37 loc) · 1.04 KB
/
handler.hpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef HANDLER_H
#define HANDLER_H
#include <string>
#include <unordered_map>
const int BUFFER_SIZE = 4096;
namespace HTTPServer {
struct StatusFD {
bool want_read = false;
bool want_write = false;
StatusFD() {}
StatusFD(bool read, bool write)
: want_read(read), want_write(write)
{}
};
const StatusFD Read{true, false};
const StatusFD Write{false, true};
const StatusFD ReadWrite{true, true};
const StatusFD Close{false, false};
class Handler {
public:
Handler(int client_fd);
~Handler();
StatusFD readRequest();
StatusFD sendResponse();
private:
// TODO: Move to separate parser class, with caching as well
void parseRequest();
void createResponse();
int client;
std::string read_req, response;
char buffer[BUFFER_SIZE];
std::unordered_map<std::string, std::string> req_headers;
// Cache for files, might be better to make this a single cache for all handlers
std::unordered_map<std::string, std::string> file_cache;
};
} // namespace HTTPServer
#endif // HANDLER_H