forked from espressif/arduino-esp32
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRequestHandler.h
91 lines (79 loc) · 1.78 KB
/
RequestHandler.h
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef REQUESTHANDLER_H
#define REQUESTHANDLER_H
#include <vector>
#include <assert.h>
class RequestHandler {
public:
virtual ~RequestHandler() {}
/*
note: old handler API for backward compatibility
*/
virtual bool canHandle(HTTPMethod method, String uri) {
(void)method;
(void)uri;
return false;
}
virtual bool canUpload(String uri) {
(void)uri;
return false;
}
virtual bool canRaw(String uri) {
(void)uri;
return false;
}
/*
note: new handler API with support for filters etc.
*/
virtual bool canHandle(WebServer &server, HTTPMethod method, String uri) {
(void)server;
(void)method;
(void)uri;
return false;
}
virtual bool canUpload(WebServer &server, String uri) {
(void)server;
(void)uri;
return false;
}
virtual bool canRaw(WebServer &server, String uri) {
(void)server;
(void)uri;
return false;
}
virtual bool handle(WebServer &server, HTTPMethod requestMethod, String requestUri) {
(void)server;
(void)requestMethod;
(void)requestUri;
return false;
}
virtual void upload(WebServer &server, String requestUri, HTTPUpload &upload) {
(void)server;
(void)requestUri;
(void)upload;
}
virtual void raw(WebServer &server, String requestUri, HTTPRaw &raw) {
(void)server;
(void)requestUri;
(void)raw;
}
virtual RequestHandler &setFilter(std::function<bool(WebServer &)> filter) {
(void)filter;
return *this;
}
RequestHandler *next() {
return _next;
}
void next(RequestHandler *r) {
_next = r;
}
private:
RequestHandler *_next = nullptr;
protected:
std::vector<String> pathArgs;
public:
const String &pathArg(unsigned int i) {
assert(i < pathArgs.size());
return pathArgs[i];
}
};
#endif //REQUESTHANDLER_H