File tree 2 files changed +59
-0
lines changed
libraries/WebServer/src/detail
2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 7
7
class RequestHandler {
8
8
public:
9
9
virtual ~RequestHandler () {}
10
+
11
+ /*
12
+ note: old handler API for backward compatibility
13
+ */
14
+
15
+ virtual bool canHandle (HTTPMethod method, String uri) {
16
+ (void )method;
17
+ (void )uri;
18
+ return false ;
19
+ }
20
+ virtual bool canUpload (String uri) {
21
+ (void )uri;
22
+ return false ;
23
+ }
24
+ virtual bool canRaw (String uri) {
25
+ (void )uri;
26
+ return false ;
27
+ }
28
+
29
+ /*
30
+ note: new handler API with support for filters etc.
31
+ */
32
+
10
33
virtual bool canHandle (WebServer &server, HTTPMethod method, String uri) {
11
34
(void )server;
12
35
(void )method;
Original file line number Diff line number Diff line change @@ -21,6 +21,30 @@ class FunctionRequestHandler : public RequestHandler {
21
21
delete _uri;
22
22
}
23
23
24
+ bool canHandle (HTTPMethod requestMethod, String requestUri) override {
25
+ if (_method != HTTP_ANY && _method != requestMethod) {
26
+ return false ;
27
+ }
28
+
29
+ return _uri->canHandle (requestUri, pathArgs);
30
+ }
31
+
32
+ bool canUpload (String requestUri) override {
33
+ if (!_ufn || !canHandle (HTTP_POST, requestUri)) {
34
+ return false ;
35
+ }
36
+
37
+ return true ;
38
+ }
39
+
40
+ bool canRaw (String requestUri) override {
41
+ if (!_ufn || _method == HTTP_GET) {
42
+ return false ;
43
+ }
44
+
45
+ return true ;
46
+ }
47
+
24
48
bool canHandle (WebServer &server, HTTPMethod requestMethod, String requestUri) override {
25
49
if (_method != HTTP_ANY && _method != requestMethod) {
26
50
return false ;
@@ -94,6 +118,18 @@ class StaticRequestHandler : public RequestHandler {
94
118
_baseUriLength = _uri.length ();
95
119
}
96
120
121
+ bool canHandle (HTTPMethod requestMethod, String requestUri) override {
122
+ if (requestMethod != HTTP_GET) {
123
+ return false ;
124
+ }
125
+
126
+ if ((_isFile && requestUri != _uri) || !requestUri.startsWith (_uri)) {
127
+ return false ;
128
+ }
129
+
130
+ return true ;
131
+ }
132
+
97
133
bool canHandle (WebServer &server, HTTPMethod requestMethod, String requestUri) override {
98
134
if (requestMethod != HTTP_GET) {
99
135
return false ;
You can’t perform that action at this time.
0 commit comments