ESP32 HTTPS Server

ResourceResolver.hpp
1 #ifndef SRC_RESOURCERESOLVER_HPP_
2 #define SRC_RESOURCERESOLVER_HPP_
3
4 #include <string>
5 // Arduino declares it's own min max, incompatible with the stl...
6 #undef min
7 #undef max
8 #include <vector>
9 #include <algorithm>
10
11 #include "HTTPNode.hpp"
12 #include "WebsocketNode.hpp"
13 #include "ResourceNode.hpp"
14 #include "ResolvedResource.hpp"
15 #include "HTTPMiddlewareFunction.hpp"
16
17 namespace httpsserver {
18
22 class ResourceResolver {
23 public:
24 ResourceResolver();
25 ~ResourceResolver();
26
27 void registerNode(HTTPNode *node);
28 void unregisterNode(HTTPNode *node);
29 void setDefaultNode(HTTPNode *node);
30 void resolveNode(const std::string &method, const std::string &url, ResolvedResource &resolvedResource, HTTPNodeType nodeType);
31
33 void addMiddleware(const HTTPSMiddlewareFunction * mwFunction);
35 void removeMiddleware(const HTTPSMiddlewareFunction * mwFunction);
37 const std::vector<HTTPSMiddlewareFunction*> getMiddleware();
38
39 private:
40
41 // This vector holds all nodes (with callbacks) that are registered
42 std::vector<HTTPNode*> * _nodes;
43 HTTPNode * _defaultNode;
44
45 // Middleware functions, if any are registered. Will be called in order of the vector.
46 std::vector<const HTTPSMiddlewareFunction*> _middleware;
47 };
48
49 } /* namespace httpsserver */
50
51 #endif /* SRC_RESOURCERESOLVER_HPP_ */
httpsserver::HTTPNode
Base class for a URL/route-handler in the server.
Definition: HTTPNode.hpp:26
httpsserver::ResourceResolver
This class is used internally to resolve a string URL to the corresponding HTTPNode.
Definition: ResourceResolver.hpp:22
httpsserver::HTTPNodeType
HTTPNodeType
Definition: HTTPNode.hpp:13
httpsserver::ResourceResolver::unregisterNode
void unregisterNode(HTTPNode *node)
Definition: ResourceResolver.cpp:24
httpsserver::ResourceResolver::registerNode
void registerNode(HTTPNode *node)
Definition: ResourceResolver.cpp:17
httpsserver::ResourceResolver::addMiddleware
void addMiddleware(const HTTPSMiddlewareFunction *mwFunction)
Definition: ResourceResolver.cpp:180
httpsserver::ResourceResolver::getMiddleware
const std::vector< HTTPSMiddlewareFunction * > getMiddleware()
Definition: ResourceResolver.cpp:188
httpsserver
Definition: ConnectionContext.cpp:3
httpsserver::ResolvedResource
This class represents a resolved resource, meaning the result of mapping a string URL to an HTTPNode...
Definition: ResolvedResource.hpp:12
httpsserver::ResourceResolver::removeMiddleware
void removeMiddleware(const HTTPSMiddlewareFunction *mwFunction)
Definition: ResourceResolver.cpp:184
httpsserver::HTTPSMiddlewareFunction
void() HTTPSMiddlewareFunction(HTTPRequest *req, HTTPResponse *res, std::function< void()> next)
A middleware function that can be registered at the server.
Definition: HTTPMiddlewareFunction.hpp:24