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

#include <RouterDispatcher.h>

Inheritance diagram for express::dispatcher::RouterDispatcher:
Collaboration diagram for express::dispatcher::RouterDispatcher:

Public Member Functions

std::list< express::Route > & getRoutes ()
 
std::list< std::string > getRoutes (const std::string &parentMountPath, const MountPoint &mountPoint) const
 
bool setStrictRouting (bool strictRouting)
 
bool getStrictRouting () const
 
- 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

std::list< express::Routeroutes
 
bool strictRouting = false
 

Additional Inherited Members

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

Detailed Description

Definition at line 60 of file RouterDispatcher.h.

Member Function Documentation

◆ dispatch()

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

Implements express::Dispatcher.

Definition at line 75 of file RouterDispatcher.cpp.

75 {
76 bool dispatched = false;
77
78 const std::string absoluteMountPath = parentMountPath + mountPoint.relativeMountPath;
79
80 const std::string requestMethod = controller.getRequest()->method;
81 const std::string requestUrl = controller.getRequest()->url;
82 const std::string requestPath = controller.getRequest()->path;
83
84 // clang-format off
85 const bool requestMatched =
86 (
87 (
88 (
89 mountPoint.method == controller.getRequest()->method
90 ) || (
91 mountPoint.method == "all"
92 ) || (
93 mountPoint.method == "use"
94 )
95 ) && (
96 (
97 requestUrl.starts_with(absoluteMountPath)
98 )
99 )
100 );
101 // clang-format on
102
103 LOG(TRACE) << "Express: R - RequestUrl: " << controller.getRequest()->url;
104 LOG(TRACE) << "Express: R - RequestPath: " << controller.getRequest()->path;
105 LOG(TRACE) << "Express: R - AbsoluteMountPath: " << absoluteMountPath;
106 LOG(TRACE) << "Express: R - StrictRouting: " << controller.getStrictRouting();
107
108 if (requestMatched) {
109 LOG(TRACE) << " MATCH";
110 for (Route& route : routes) {
111 const bool oldStrictRouting = controller.setStrictRouting(strictRouting);
112
113 dispatched = route.dispatch(controller, absoluteMountPath);
114
115 controller.setStrictRouting(oldStrictRouting);
116
117 if (dispatched) {
118 LOG(TRACE) << "Express: R - Dispatched: " << dispatched;
119 }
120 if (controller.nextRouterCalled()) {
121 LOG(TRACE) << "Express: R - NextRouter called - breaking dispatching";
122 }
123 if (dispatched || controller.nextRouterCalled()) {
124 break;
125 }
126 }
127 } else {
128 LOG(TRACE) << " NO MQTCH";
129 }
130
131 return dispatched;
132 }
const std::shared_ptr< Request > & getRequest()
bool setStrictRouting(bool strictRouting)
bool getStrictRouting() const
friend class Route
Definition Dispatcher.h:81
std::list< express::Route > routes
std::string method
Definition MountPoint.h:56
std::string relativeMountPath
Definition MountPoint.h:57

References express::Route::dispatch(), express::Controller::getRequest(), express::Controller::getStrictRouting(), express::MountPoint::method, express::Request::method, express::Controller::nextRouterCalled(), express::Request::path, express::MountPoint::relativeMountPath, routes, express::Controller::setStrictRouting(), strictRouting, and express::Request::url.

Here is the call graph for this function:

◆ getRoutes() [1/3]

std::list< Route > & express::dispatcher::RouterDispatcher::getRoutes ( )

Definition at line 58 of file RouterDispatcher.cpp.

58 {
59 return routes;
60 }

References routes.

Referenced by express::RootRoute::routes().

Here is the caller graph for this function:

◆ getRoutes() [2/3]

std::list< std::string > express::dispatcher::RouterDispatcher::getRoutes ( const std::string &  parentMountPath,
const MountPoint mountPoint 
) const

Definition at line 134 of file RouterDispatcher.cpp.

134 {
135 return getRoutes(parentMountPath, mountPoint, strictRouting);
136 }
std::list< express::Route > & getRoutes()

References getRoutes(), and strictRouting.

Referenced by express::RootRoute::getRoutes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getRoutes() [3/3]

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

Implements express::Dispatcher.

Definition at line 139 of file RouterDispatcher.cpp.

139 {
140 std::list<std::string> collectedRoutes;
141
142 for (const Route& route : routes) {
143 collectedRoutes.splice(
144 collectedRoutes.end(),
145 route.getRoute(parentMountPath + "$" + mountPoint.relativeMountPath + "$", this->strictRouting ? true : strictRouting));
146 }
147
148 return collectedRoutes;
149 }

References express::Route::getRoute(), express::MountPoint::relativeMountPath, routes, and strictRouting.

Referenced by getRoutes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getStrictRouting()

bool express::dispatcher::RouterDispatcher::getStrictRouting ( ) const

Definition at line 70 of file RouterDispatcher.cpp.

70 {
71 return strictRouting;
72 }

References strictRouting.

Referenced by express::RootRoute::dispatch(), and express::RootRoute::setStrictRouting().

Here is the caller graph for this function:

◆ setStrictRouting()

bool express::dispatcher::RouterDispatcher::setStrictRouting ( bool  strictRouting)

Definition at line 62 of file RouterDispatcher.cpp.

62 {
63 const bool oldStrictRouting = this->strictRouting;
64
66
67 return oldStrictRouting;
68 }

References strictRouting.

Referenced by express::RootRoute::setStrictRouting().

Here is the caller graph for this function:

Member Data Documentation

◆ routes

std::list<express::Route> express::dispatcher::RouterDispatcher::routes
private

Definition at line 75 of file RouterDispatcher.h.

Referenced by dispatch(), getRoutes(), and getRoutes().

◆ strictRouting

bool express::dispatcher::RouterDispatcher::strictRouting = false
private

Definition at line 77 of file RouterDispatcher.h.

Referenced by dispatch(), getRoutes(), getRoutes(), getStrictRouting(), and setStrictRouting().


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