Newer
Older
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
54
55
56
57
58
#ifndef _HTTP_ROUTE_HPP
#define _HTTP_ROUTE_HPP
#include <functional>
#include <string>
#include <regex>
#include "http_request.hpp"
#include "http_response.hpp"
enum class HttpRouteHandling
{
/**
* @brief End the connection after the route was handled.
*/
End,
/**
* @brief Continue trying to match the route with other handlers.
*/
Continue
};
typedef std::function<HttpRouteHandling (const HttpRequest &req, HttpResponse &res)> HttpHandlerFn;
class HttpRoute
{
public:
enum class MatchType
{
Regex,
StartsWith,
Literal,
MatchAny
};
private:
std::string route;
std::regex route_matcher;
HttpRoute::MatchType matchType;
HttpHandlerFn handler_fn;
public:
HttpRoute(const std::string &route, HttpHandlerFn handler,
HttpRoute::MatchType matchType = HttpRoute::MatchType::Regex);
const std::string & getRoute() const;
const HttpRoute::MatchType & getMatchType() const;
friend class HttpServer;
};
#endif // _HTTP_ROUTE_HPP