-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.hpp
60 lines (47 loc) · 1.3 KB
/
Module.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
54
55
56
57
58
59
60
#pragma once
#include <variant>
#include <vector>
#include "Request.hpp"
#include "Response.hpp"
namespace zia {
using ConfigValue = std::variant<std::string, std::vector<std::string>, int, bool>;
using Config = std::map<std::string, ConfigValue>;
enum class ExecState {
/**
* Right after te request is received
*/
Before,
/**
* While request is handled
*/
During,
/**
* Right before the response is sent
*/
Last,
/**
* After the response is sent back
*/
After,
};
class Module {
public:
/**
* When represents the steps during request handling when the module expects to be called.
* @return A vector of ExecState values
*/
virtual std::vector<ExecState> when() = 0;
/**
* Exec is the main method of a module. It will be called by the core whenever the core decides to invoke the module.
* @param request The Request object
* @param response The Response object
* @param when The time during execution where this module was called
*/
virtual void exec(http::Request &request, http::Response &response, ExecState when) = 0;
/**
* Lets the module store it's config.
* @param config A map of every config parameters
*/
virtual void loadConfig(Config &config) = 0;
};
}