SNode.C
Loading...
Searching...
No Matches
express::dispatcher::MiddlewareDispatcher Class Reference

#include <MiddlewareDispatcher.h>

Inheritance diagram for express::dispatcher::MiddlewareDispatcher:
Collaboration diagram for express::dispatcher::MiddlewareDispatcher:

Public Member Functions

 MiddlewareDispatcher (const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &, express::Next &)> &lambda)
 
- Public Member Functions inherited from express::Dispatcher
 Dispatcher (const Dispatcher &)=delete
 
Dispatcheroperator= (const Dispatcher &)=delete
 
 Dispatcher ()=default
 
virtual ~Dispatcher ()
 
bool dispatchNext (Controller &controller, const std::string &parentMountPath)
 

Private Member Functions

bool dispatch (express::Controller &controller, const std::string &parentMountPath, const express::MountPoint &mountPoint) override
 
std::list< std::string > getRoutes (const std::string &parentMountPath, const MountPoint &mountPoint, bool strictRouting) const override
 

Private Attributes

const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &, express::Next &)> lambda
 

Additional Inherited Members

- Protected Attributes inherited from express::Dispatcher
std::shared_ptr< RoutenextRoute = nullptr
 

Detailed Description

Definition at line 63 of file MiddlewareDispatcher.h.

Constructor & Destructor Documentation

◆ MiddlewareDispatcher()

express::dispatcher::MiddlewareDispatcher::MiddlewareDispatcher ( const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &, express::Next &)> &  lambda)
explicit

Definition at line 59 of file MiddlewareDispatcher.cpp.

61 : lambda(lambda) {
62 }
const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &, express::Next &)> lambda

References lambda.

Member Function Documentation

◆ dispatch()

bool express::dispatcher::MiddlewareDispatcher::dispatch ( express::Controller controller,
const std::string &  parentMountPath,
const express::MountPoint mountPoint 
)
overrideprivatevirtual

Implements express::Dispatcher.

Definition at line 64 of file MiddlewareDispatcher.cpp.

64 {
65 bool requestMatched = false;
66
67 if ((controller.getFlags() & Controller::NEXT) == 0) {
68 const std::string absoluteMountPath = parentMountPath + mountPoint.relativeMountPath;
69
70 const std::string requestMethod = controller.getRequest()->method;
71 const std::string requestUrl = controller.getRequest()->url;
72 const std::string requestPath = controller.getRequest()->path;
73
74 // clang-format off
75 requestMatched =
76 (
77 (
78 (
79 mountPoint.method == requestMethod
80 ) || (
81 mountPoint.method == "all"
82 )
83 ) && (
84 (
85 requestUrl == absoluteMountPath
86 ) || (
87 (
88 !controller.getStrictRouting()
89 ) && (
90 requestPath.starts_with(absoluteMountPath)
91 )
92 ) || (
93 checkForUrlMatch(absoluteMountPath, requestUrl)
94 )
95 )
96 ) || (
97 (
98 mountPoint.method == "use"
99 ) && (
100 (
101 requestUrl.starts_with(absoluteMountPath)
102 )
103 )
104 );
105 // clang-format on
106
107 LOG(TRACE) << "Express: M - RequestUrl: " << controller.getRequest()->url;
108 LOG(TRACE) << "Express: M - RequestPath: " << controller.getRequest()->path;
109 LOG(TRACE) << "Express: M - AbsoluteMountPath: " << absoluteMountPath;
110 LOG(TRACE) << "Express: M - StrictRouting: " << controller.getStrictRouting();
111
112 if (requestMatched) {
113 LOG(TRACE) << " MATCH";
114 if (hasResult(absoluteMountPath)) {
115 setParams(absoluteMountPath, *controller.getRequest());
116 }
117
118 Next next(controller);
119 lambda(controller.getRequest(), controller.getResponse(), next);
120
121 // If next() was called synchronously continue current route-tree traversal
122 if ((next.controller.getFlags() & express::Controller::NEXT) != 0) {
123 LOG(TRACE) << "Express: M - Next called - set to NO MATCH";
124 requestMatched = false;
125 controller = next.controller;
126 }
127 } else {
128 LOG(TRACE) << " NO MQTCH";
129 }
130 }
131
132 return requestMatched;
133 }
const std::shared_ptr< Request > & getRequest()
bool getStrictRouting() const
const std::shared_ptr< Response > & getResponse()
bool checkForUrlMatch(const std::string &cpath, const std::string &reqpath)
void setParams(const std::string &cpath, express::Request &req)
bool hasResult(const std::string &cpath)
std::string method
Definition MountPoint.h:56
std::string relativeMountPath
Definition MountPoint.h:57

References express::dispatcher::checkForUrlMatch(), express::Next::controller, express::Controller::getFlags(), express::Controller::getRequest(), express::Controller::getResponse(), express::Controller::getStrictRouting(), express::dispatcher::hasResult(), lambda, express::MountPoint::method, express::Request::method, express::Controller::NEXT, express::Next::Next(), express::Controller::operator=(), express::Request::path, express::MountPoint::relativeMountPath, express::dispatcher::setParams(), and express::Request::url.

Here is the call graph for this function:

◆ getRoutes()

std::list< std::string > express::dispatcher::MiddlewareDispatcher::getRoutes ( const std::string &  parentMountPath,
const MountPoint mountPoint,
bool  strictRouting 
) const
overrideprivatevirtual

Implements express::Dispatcher.

Definition at line 136 of file MiddlewareDispatcher.cpp.

136 {
137 std::list<std::string> routes{"M " + parentMountPath + mountPoint.relativeMountPath + (!strictRouting ? "*" : "")};
138 routes.push_back(" " + mountPoint.method + " " + mountPoint.relativeMountPath);
139
140 if (nextRoute) {
141 routes.splice(routes.end(), nextRoute->getRoute(parentMountPath, strictRouting));
142 }
143
144 return routes;
145 }
std::shared_ptr< Route > nextRoute
Definition Dispatcher.h:78

References express::Route::getRoute(), express::MountPoint::method, express::Dispatcher::nextRoute, and express::MountPoint::relativeMountPath.

Here is the call graph for this function:

Member Data Documentation

◆ lambda

const std::function<void(const std::shared_ptr<Request>&, const std::shared_ptr<Response>&, express::Next&)> express::dispatcher::MiddlewareDispatcher::lambda
private

Definition at line 73 of file MiddlewareDispatcher.h.

Referenced by dispatch(), and MiddlewareDispatcher().


The documentation for this class was generated from the following files: