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

RouterDispatchersetStrictRouting (bool strictRouting)
bool getStrictRouting () const
RouterDispatchersetCaseInsensitiveRouting (bool caseInsensitiveRouting)
bool getCaseInsensitiveRouting () const
RouterDispatchersetMergeParams (bool mergeParams)
bool getMergeParams () const
std::list< express::Route > & getRoutes ()
std::list< std::string > getRoutes (const std::string &parentMountPath, const MountPoint &mountPoint) const
Public Member Functions inherited from express::Dispatcher
 Dispatcher (const Dispatcher &)=delete
Dispatcheroperator= (const Dispatcher &)=delete
 Dispatcher ()=default
virtual ~Dispatcher ()
bool dispatchNext (Controller &controller, bool strictRouting, bool caseInsensitiveRouting, bool mergeParams)

Private Member Functions

bool dispatch (express::Controller &controller, const express::MountPoint &mountPoint, bool strictRoutingUnused, bool caseInsensitiveRoutingUnused, bool mergeParamsUnused) 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
bool caseInsensitiveRouting = true
bool mergeParams = false
std::regex regex
std::vector< std::string > names

Additional Inherited Members

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

Detailed Description

Definition at line 62 of file RouterDispatcher.h.

Member Function Documentation

◆ dispatch()

bool express::dispatcher::RouterDispatcher::dispatch ( express::Controller & controller,
const express::MountPoint & mountPoint,
bool strictRoutingUnused,
bool caseInsensitiveRoutingUnused,
bool mergeParamsUnused )
overrideprivatevirtual

Implements express::Dispatcher.

Definition at line 67 of file RouterDispatcher.cpp.

71 {
72 LOG(TRACE) << "======================= ROUTER DISPATCH =======================";
73 LOG(TRACE) << controller.getResponse()->getSocketContext()->getSocketConnection()->getConnectionName();
74 LOG(TRACE) << " Request Method: " << controller.getRequest()->method;
75 LOG(TRACE) << " Request Url: " << controller.getRequest()->url;
76 LOG(TRACE) << " Request Path: " << controller.getRequest()->path;
77 LOG(TRACE) << " Mountpoint Method: " << mountPoint.method;
78 LOG(TRACE) << " Mountpoint Path: " << mountPoint.relativeMountPath;
79 LOG(TRACE) << " StrictRouting: " << this->strictRouting;
80 LOG(TRACE) << " CaseInsensitiveRouting: " << this->caseInsensitiveRouting;
81 LOG(TRACE) << " MergeParams: " << this->mergeParams;
82
83 bool dispatched = false;
84
85 const bool methodMatchesResult = methodMatches(controller.getRequest()->method, mountPoint.method);
86
87 if (methodMatchesResult && (controller.getFlags() & Controller::NEXT) == 0) {
88 const MountMatchResult match = matchMountPoint(
89 controller, mountPoint.relativeMountPath, mountPoint, regex, names, this->strictRouting, this->caseInsensitiveRouting);
90
91 if (match.requestMatched) {
92 LOG(TRACE) << "----------------------- ROUTER MATCH -----------------------";
93
94 dispatched = true;
95
96 if (!match.decodeError) {
97 express::Request& request = *controller.getRequest();
98 request.queries.insert(match.requestQueryPairs.begin(), match.requestQueryPairs.end());
99
100 // Express-style mount path stripping is only applied for use()
101 const ScopedPathStrip pathStrip(request, match.isPrefix, match.consumedLength);
102 const ScopedParams scopedParams(request, match.params, this->mergeParams);
103
104 for (Route& route : routes) {
105 dispatched = route.dispatch(controller, this->strictRouting, this->caseInsensitiveRouting, this->mergeParams);
106
107 if (dispatched || controller.nextRouterCalled()) {
108 break;
109 }
110 }
111 } else {
112 controller.getResponse()->sendStatus(400);
113 }
114 } else {
115 LOG(TRACE) << "----------------------- ROUTER NOMATCH -----------------------";
116 }
117 } else {
118 LOG(TRACE) << "----------------------- ROUTER NOMATCH -----------------------";
119 }
120
121 return dispatched;
122 }
#define LOG(level)
Definition Logger.h:148
const std::shared_ptr< Request > & getRequest() const
const std::shared_ptr< Response > & getResponse() const
bool nextRouterCalled() const
friend class Route
Definition Dispatcher.h:83
std::map< std::string, std::string > queries
Definition Request.h:103
std::list< express::Route > routes
bool match(const char *first, const char *second)
MountMatchResult matchMountPoint(express::Controller &controller, const std::string &absoluteMountPath, const express::MountPoint &mountPoint, std::regex &cachedRegex, std::vector< std::string > &cachedNames, bool strictRouting, bool caseInsensitiveRouting)
bool methodMatches(std::string_view requestMethod, const std::string &mountMethod)
std::string method
Definition MountPoint.h:56
std::string relativeMountPath
Definition MountPoint.h:57

References caseInsensitiveRouting, express::dispatcher::MountMatchResult::consumedLength, express::dispatcher::MountMatchResult::decodeError, express::Route::dispatch(), core::socket::stream::SocketConnection::getConnectionName(), express::Controller::getFlags(), express::Controller::getRequest(), express::Controller::getResponse(), core::socket::stream::SocketContext::getSocketConnection(), express::Response::getSocketContext(), express::dispatcher::MountMatchResult::isPrefix, logger::LogMessage::LogMessage(), express::dispatcher::matchMountPoint(), mergeParams, express::MountPoint::method, express::Request::method, express::dispatcher::methodMatches(), names, express::Controller::NEXT, express::Controller::nextRouterCalled(), express::dispatcher::MountMatchResult::params, express::Request::path, express::Request::queries, express::MountPoint::relativeMountPath, express::dispatcher::MountMatchResult::requestMatched, express::dispatcher::MountMatchResult::requestQueryPairs, routes, express::dispatcher::ScopedParams::ScopedParams(), express::dispatcher::ScopedPathStrip::ScopedPathStrip(), express::Response::sendStatus(), strictRouting, logger::TRACE, and express::Request::url.

Here is the call graph for this function:

◆ getCaseInsensitiveRouting()

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

Definition at line 156 of file RouterDispatcher.cpp.

156 {
158 }

References caseInsensitiveRouting.

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

Here is the caller graph for this function:

◆ getMergeParams()

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

Definition at line 166 of file RouterDispatcher.cpp.

166 {
167 return mergeParams;
168 }

References mergeParams.

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

Here is the caller graph for this function:

◆ getRoutes() [1/3]

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

Definition at line 63 of file RouterDispatcher.cpp.

63 {
64 return routes;
65 }

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

124 {
125 return getRoutes(parentMountPath, mountPoint, false);
126 }
std::list< express::Route > & getRoutes()

References getRoutes().

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

129 {
130 std::list<std::string> collectedRoutes;
131
132 for (const Route& route : routes) {
133 collectedRoutes.splice(collectedRoutes.end(),
134 route.getRoute(parentMountPath + "$" + mountPoint.relativeMountPath + "$", strictRouting));
135 }
136
137 return collectedRoutes;
138 }

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

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

146 {
147 return strictRouting;
148 }

References strictRouting.

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

Here is the caller graph for this function:

◆ setCaseInsensitiveRouting()

RouterDispatcher & express::dispatcher::RouterDispatcher::setCaseInsensitiveRouting ( bool caseInsensitiveRouting)

Definition at line 150 of file RouterDispatcher.cpp.

150 {
152
153 return *this;
154 }

References caseInsensitiveRouting.

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

Here is the caller graph for this function:

◆ setMergeParams()

RouterDispatcher & express::dispatcher::RouterDispatcher::setMergeParams ( bool mergeParams)

Definition at line 160 of file RouterDispatcher.cpp.

160 {
161 this->mergeParams = mergeParams;
162
163 return *this;
164 }

References mergeParams.

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

Here is the caller graph for this function:

◆ setStrictRouting()

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

Definition at line 140 of file RouterDispatcher.cpp.

140 {
142
143 return *this;
144 }

References strictRouting.

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

Here is the caller graph for this function:

Member Data Documentation

◆ caseInsensitiveRouting

bool express::dispatcher::RouterDispatcher::caseInsensitiveRouting = true
private

◆ mergeParams

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

Definition at line 91 of file RouterDispatcher.h.

Referenced by dispatch(), getMergeParams(), and setMergeParams().

◆ names

std::vector<std::string> express::dispatcher::RouterDispatcher::names
private

Definition at line 94 of file RouterDispatcher.h.

Referenced by dispatch().

◆ regex

std::regex express::dispatcher::RouterDispatcher::regex
private

Definition at line 93 of file RouterDispatcher.h.

◆ routes

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

Definition at line 87 of file RouterDispatcher.h.

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

◆ strictRouting

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

Definition at line 89 of file RouterDispatcher.h.

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


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