forked from fhessel/esp32_https_server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTTPNode.hpp
More file actions
65 lines (51 loc) · 1.72 KB
/
HTTPNode.hpp
File metadata and controls
65 lines (51 loc) · 1.72 KB
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
61
62
63
64
65
#ifndef SRC_HTTPNODE_HPP_
#define SRC_HTTPNODE_HPP_
#include <Arduino.h>
#include <string>
#undef min
#undef max
#include <vector>
#include "HTTPValidator.hpp"
namespace httpsserver {
enum HTTPNodeType {
/** Node with a handler callback function (class ResourceNode) */
HANDLER_CALLBACK,
/** Node with a websocket handler (class WebsocketNode) */
WEBSOCKET
};
class HTTPNode {
public:
HTTPNode(const std::string path, const HTTPNodeType nodeType, const std::string tag = "");
virtual ~HTTPNode();
/**
* The path under which this node will be available. Should start with a slash. Example:
* "/myResource"
*/
const std::string _path;
/**
* Stores a tag that can be used in middleware and handler functions to identify this
* specific node, tag the node with a required permission, ...
*/
const std::string _tag;
/** Stores the type of the node (as we have not runtime type information by default) */
const HTTPNodeType _nodeType;
bool hasUrlParameter();
uint8_t getUrlParamCount();
size_t getParamIdx(uint8_t);
std::vector<HTTPValidator*> * getValidators();
virtual std::string getMethod() = 0;
/**
* Adds a validation function that checks if the actual value of a parameter matches the expectation
* @param paramIdx defines the ID of the parameter that should be checked (starts by 0)
* @param validator the function (string -> bool) that checks if the parameter matches the expecatation
*
* @see ValidatorFunctions.hpp if you need some predefined templates for functions
*/
void addURLParamValidator(uint8_t paramIdx, const HTTPValidationFunction * validator);
private:
uint8_t _urlParamCount;
size_t * _urlParamIdx;
std::vector<HTTPValidator*> * _validators;
};
} // namespace httpserver
#endif