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

#include <ApplicationDispatcher.h>

Inheritance diagram for express::dispatcher::ApplicationDispatcher:
Collaboration diagram for express::dispatcher::ApplicationDispatcher:

Public Member Functions

 ApplicationDispatcher (const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &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 > &)> lambda
 

Additional Inherited Members

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

Detailed Description

Definition at line 62 of file ApplicationDispatcher.h.

Constructor & Destructor Documentation

◆ ApplicationDispatcher()

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

Definition at line 59 of file ApplicationDispatcher.cpp.

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

References lambda.

Member Function Documentation

◆ dispatch()

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

Implements express::Dispatcher.

Definition at line 64 of file ApplicationDispatcher.cpp.

66 {
67 bool requestMatched = false;
68
69 if ((controller.getFlags() & Controller::NEXT) == 0) {
70 const std::string absoluteMountPath = parentMountPath + mountPoint.relativeMountPath;
71
72 const std::string requestMethod = controller.getRequest()->method;
73 const std::string requestUrl = controller.getRequest()->url;
74 const std::string requestPath = controller.getRequest()->path;
75
76 // clang-format off
77 requestMatched =
78 (
79 (
80 (
81 mountPoint.method == requestMethod
82 ) || (
83 mountPoint.method == "all"
84 )
85 ) && (
86 (
87 requestUrl == absoluteMountPath
88 ) || (
89 (
90 !controller.getStrictRouting()
91 ) && (
92 requestUrl.starts_with(absoluteMountPath)
93 )
94 ) || (
95 checkForUrlMatch(absoluteMountPath, requestUrl)
96 )
97 )
98 ) || (
99 (
100 mountPoint.method == "use"
101 ) && (
102 (
103 requestUrl.starts_with(absoluteMountPath)
104 )
105 )
106 );
107 // clang-format on
108
109 LOG(TRACE) << "Express: A - RequestUrl: " << controller.getRequest()->url;
110 LOG(TRACE) << "Express: A - RequestPath: " << controller.getRequest()->path;
111 LOG(TRACE) << "Express: A - AbsoluteMountPath: " << absoluteMountPath;
112 LOG(TRACE) << "Express: A - StrictRouting: " << controller.getStrictRouting();
113
114 if (requestMatched) {
115 LOG(TRACE) << " MATCH";
116 if (hasResult(absoluteMountPath)) {
117 setParams(absoluteMountPath, *controller.getRequest());
118 }
119
120 lambda(controller.getRequest(), controller.getResponse());
121 } else {
122 LOG(TRACE) << " NO MQTCH";
123 }
124 }
125
126 return requestMatched;
127 }
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::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::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::ApplicationDispatcher::getRoutes ( const std::string &  parentMountPath,
const MountPoint mountPoint,
bool  strictRouting 
) const
overrideprivatevirtual

Implements express::Dispatcher.

Definition at line 130 of file ApplicationDispatcher.cpp.

130 {
131 std::list<std::string> routes{"A " + parentMountPath + mountPoint.relativeMountPath + (!strictRouting ? "*" : "")};
132 routes.push_back(" " + mountPoint.method + " " + mountPoint.relativeMountPath);
133
134 if (nextRoute) {
135 routes.splice(routes.end(), nextRoute->getRoute(parentMountPath, strictRouting));
136 }
137
138 return routes;
139 }
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::dispatcher::ApplicationDispatcher::lambda
private

Definition at line 72 of file ApplicationDispatcher.h.

Referenced by ApplicationDispatcher(), and dispatch().


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