-
Notifications
You must be signed in to change notification settings - Fork 13.3k
/
Copy pathRequestHandler.h
41 lines (32 loc) · 1.27 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
#ifndef REQUESTHANDLER_H
#define REQUESTHANDLER_H
#include <ESP8266WebServer.h>
#include <vector>
#include <assert.h>
namespace esp8266webserver {
template<typename ServerType>
class RequestHandler {
using WebServerType = ESP8266WebServerTemplate<ServerType>;
public:
virtual ~RequestHandler() { }
virtual bool canHandle(HTTPMethod method, const String& uri) { (void) method; (void) uri; return false; }
virtual bool canUpload(const String& uri) { (void) uri; return false; }
virtual bool handle(WebServerType& server, HTTPMethod requestMethod, const String& requestUri) { (void) server; (void) requestMethod; (void) requestUri; return false; }
virtual void upload(WebServerType& server, const String& requestUri, HTTPUpload& upload) { (void) server; (void) requestUri; (void) upload; }
RequestHandler<ServerType>* next() { return _next; }
void next(RequestHandler<ServerType>* r) { _next = r; }
private:
RequestHandler<ServerType>* _next = nullptr;
protected:
std::vector<String> currentPathArgs;
public:
const String& pathArg(unsigned int i) {
assert(i < currentPathArgs.size());
return currentPathArgs[i];
}
const int pathArgs() {
return currentPathArgs.size();
}
};
} // namespace
#endif //REQUESTHANDLER_H