Newer
Older
#ifndef _HTTPD_HPP
#define _HTTPD_HPP
#include <regex>
#include <string>
#include <unordered_map>
#include <functional>
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
54
55
56
57
58
#include "http_err.hpp"
#include "http_request.hpp"
#include "http_response.hpp"
#include "http_route.hpp"
#include "threadpool.hpp"
class HttpServer
{
private:
ssize_t tcp_read_buffer_size = 4096;
int pendingConnections = 5;
int queuedConnections = 5;
int numberOfThreads = Threadpool::AUTO_NO_WORKERS;
std::string ip;
in_addr ip_inaddr;
uint16_t port;
std::vector<HttpRoute> routes;
static HttpRouteHandling defaultHandlerFunction(const HttpRequest &req, HttpResponse & res);
HttpHandlerFn defaultHandler = &defaultHandlerFunction;
void handleConnection(int sockfd, const std::string &ip, uint16_t port);
public:
HttpServer(uint16_t port, std::string ip = "0.0.0.0");
void addRoute(const HttpRoute &route)
{
routes.push_back(route);
}
void setDefaultHandler(const HttpHandlerFn &);
void serveForever();
};
#endif // _HTTPD_HPP