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 76 of file RouterDispatcher.cpp.

76 {
77 bool dispatched = false;
78
79 const std::string absoluteMountPath = parentMountPath + mountPoint.relativeMountPath;
80
81 const std::string requestMethod = controller.getRequest()->method;
82 const std::string requestUrl = controller.getRequest()->url;
83 const std::string requestPath = controller.getRequest()->path;
84
85 // clang-format off
86 const bool requestMatched =
87 (
88 (
89 (
90 mountPoint.method == controller.getRequest()->method
91 ) || (
92 mountPoint.method == "all"
93 ) || (
94 mountPoint.method == "use"
95 )
96 ) && (
97 (
98 requestUrl.starts_with(absoluteMountPath)
99 )
100 )
101 );
102 // clang-format on
103 LOG(TRACE) << controller.getResponse()->getSocketContext()->getSocketConnection()->getConnectionName()
104 << " HTTP Express: router -> " << (requestMatched ? "MATCH" : "NO MATCH");
105 LOG(TRACE) << " RequestMethod: " << controller.getRequest()->method;
106 LOG(TRACE) << " RequestUrl: " << controller.getRequest()->url;
107 LOG(TRACE) << " RequestPath: " << controller.getRequest()->path;
108 LOG(TRACE) << " AbsoluteMountPath: " << absoluteMountPath;
109 LOG(TRACE) << " StrictRouting: " << controller.getStrictRouting();
110 LOG(TRACE) << " StrictRouting: " << controller.getStrictRouting();
111
112 if (requestMatched) {
113 for (Route& route : routes) {
114 const bool oldStrictRouting = controller.setStrictRouting(strictRouting);
115
116 dispatched = route.dispatch(controller, absoluteMountPath);
117
118 controller.setStrictRouting(oldStrictRouting);
119
120 if (dispatched) {
121 LOG(TRACE) << "Express: R - Dispatched: " << dispatched;
122 }
123 if (controller.nextRouterCalled()) {
124 LOG(TRACE) << "Express: R - NextRouter called - breaking dispatching";
125 }
126 if (dispatched || controller.nextRouterCalled()) {
127 break;
128 }
129 }
130 }
131
132 return dispatched;
133 }
const std::shared_ptr< Request > & getRequest()
bool setStrictRouting(bool strictRouting)
bool getStrictRouting() const
const std::shared_ptr< Response > & getResponse()
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(), core::socket::stream::SocketConnection::getConnectionName(), express::Controller::getRequest(), express::Controller::getResponse(), core::socket::stream::SocketContext::getSocketConnection(), express::Response::getSocketContext(), 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 59 of file RouterDispatcher.cpp.

59 {
60 return routes;
61 }

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 135 of file RouterDispatcher.cpp.

135 {
136 return getRoutes(parentMountPath, mountPoint, strictRouting);
137 }
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 140 of file RouterDispatcher.cpp.

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

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 71 of file RouterDispatcher.cpp.

71 {
72 return strictRouting;
73 }

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 63 of file RouterDispatcher.cpp.

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

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: