forked from ESP32Async/ESPAsyncWebServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsyncRouter.cpp
More file actions
43 lines (36 loc) · 1.26 KB
/
AsyncRouter.cpp
File metadata and controls
43 lines (36 loc) · 1.26 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
#include "AsyncRouter.h"
AsyncRouter::AsyncRouter(AsyncWebServer* server, const char* path) {
_server = server;
_path = path;
}
AsyncRouter::~AsyncRouter() {
for (AsyncCallbackWebHandler* handler : _handlers) {
_server->removeHandler(handler);
delete handler;
}
}
AsyncCallbackWebHandler& AsyncRouter::on(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, ArUploadHandlerFunction onUpload, ArBodyHandlerFunction onBody) {
AsyncCallbackWebHandler& handler = _server->on(
(_path + uri).c_str(),
method,
onRequest,
onUpload,
onBody
);
_handlers.push_back(&handler);
return handler;
};
AsyncCallbackWebHandler& AsyncRouter::on(const char* uri, ArRequestHandlerFunction onRequest) {
return _server->on((_path + uri).c_str(), HTTP_ANY, onRequest);
}
AsyncCallbackWebHandler& AsyncRouter::on(const char* uri, WebRequestMethod method, ArRequestHandlerFunction onRequest) {
return _server->on((_path + uri).c_str(), method, onRequest);
}
void AsyncRouter::addMidleware(AsyncMiddleware* middleware) {
for (AsyncCallbackWebHandler* handler : _handlers) {
handler->addMiddleware(middleware);
}
}
std::string AsyncRouter::path() {
return _path;
}