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, bool strictRouting, bool caseInsensitiveRouting, bool mergeParams)

Private Member Functions

bool dispatch (express::Controller &controller, const express::MountPoint &mountPoint, bool strictRouting, bool caseInsensitiveRouting, bool mergeParams) 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
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 64 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 63 of file ApplicationDispatcher.cpp.

65 : lambda(lambda) {
66 }
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 express::MountPoint & mountPoint,
bool strictRouting,
bool caseInsensitiveRouting,
bool mergeParams )
overrideprivatevirtual

Implements express::Dispatcher.

Definition at line 68 of file ApplicationDispatcher.cpp.

72 {
73 LOG(TRACE) << "======================= APPLICATION DISPATCH =======================";
74 LOG(TRACE) << controller.getResponse()->getSocketContext()->getSocketConnection()->getConnectionName();
75 LOG(TRACE) << " Request Method: " << controller.getRequest()->method;
76 LOG(TRACE) << " Request Url: " << controller.getRequest()->url;
77 LOG(TRACE) << " Request Path: " << controller.getRequest()->path;
78 LOG(TRACE) << " Mountpoint Method: " << mountPoint.method;
79 LOG(TRACE) << " Mountpoint Path: " << mountPoint.relativeMountPath;
80 LOG(TRACE) << " StrictRouting: " << strictRouting;
81 LOG(TRACE) << " CaseInsensitiveRouting: " << caseInsensitiveRouting;
82 LOG(TRACE) << " MergeParams: " << mergeParams;
83
84 bool dispatched = false;
85
86 const bool methodMatchesResult = methodMatches(controller.getRequest()->method, mountPoint.method);
87 const bool replayingNext = (controller.getFlags() & Controller::NEXT) != 0;
88
89 if (methodMatchesResult) {
90 const MountMatchResult match =
91 matchMountPoint(controller, mountPoint.relativeMountPath, mountPoint, regex, names, strictRouting, caseInsensitiveRouting);
92
93 if (match.requestMatched) {
94 LOG(TRACE) << "----------------------- APPLICATION MATCH -----------------------";
95
96 dispatched = true;
97
98 if (!match.decodeError) {
99 express::Request& request = *controller.getRequest();
100 request.queries.insert(match.requestQueryPairs.begin(), match.requestQueryPairs.end());
101
102 // Express-style mount path stripping is only applied for use()
103 const ScopedPathStrip pathStrip(request, match.isPrefix, match.consumedLength);
104 const ScopedParams scopedParams(request, match.params, mergeParams);
105
106 if (!replayingNext) {
107 lambda(controller.getRequest(), controller.getResponse());
108 } else {
109 dispatched = controller.dispatchNext(strictRouting, caseInsensitiveRouting, mergeParams);
110 }
111 } else {
112 controller.getResponse()->sendStatus(400);
113 }
114
115 } else {
116 LOG(TRACE) << "----------------------- APPLICATION NOMATCH -----------------------";
117 }
118 } else {
119 LOG(TRACE) << "----------------------- APPLICATION NOMATCH -----------------------";
120 }
121
122 return dispatched;
123 }
#define LOG(level)
Definition Logger.h:148
bool dispatchNext(bool strictRouting, bool caseInsensitiveRouting, bool mergeParams)
const std::shared_ptr< Request > & getRequest() const
const std::shared_ptr< Response > & getResponse() const
std::map< std::string, std::string > queries
Definition Request.h:103
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 express::dispatcher::MountMatchResult::consumedLength, express::dispatcher::MountMatchResult::decodeError, express::Controller::dispatchNext(), 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, lambda, logger::LogMessage::LogMessage(), express::dispatcher::matchMountPoint(), express::MountPoint::method, express::Request::method, express::dispatcher::methodMatches(), names, express::Controller::NEXT, express::dispatcher::MountMatchResult::params, express::Request::path, express::Request::queries, express::MountPoint::relativeMountPath, express::dispatcher::MountMatchResult::requestMatched, express::dispatcher::MountMatchResult::requestQueryPairs, express::dispatcher::ScopedParams::ScopedParams(), express::dispatcher::ScopedPathStrip::ScopedPathStrip(), express::Response::sendStatus(), logger::TRACE, 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 126 of file ApplicationDispatcher.cpp.

126 {
127 std::list<std::string> routes{"A " + joinMountPath(parentMountPath, mountPoint.relativeMountPath) + (!strictRouting ? "*" : "")};
128 routes.push_back(" " + mountPoint.method + " " + mountPoint.relativeMountPath);
129
130 if (nextRoute) {
131 routes.splice(routes.end(), nextRoute->getRoute(parentMountPath, strictRouting));
132 }
133
134 return routes;
135 }
std::shared_ptr< Route > nextRoute
Definition Dispatcher.h:81
std::string joinMountPath(std::string_view parentMountPath, std::string_view relativeMountPath)

References express::Route::getRoute(), express::dispatcher::joinMountPath(), 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 79 of file ApplicationDispatcher.h.

Referenced by ApplicationDispatcher(), and dispatch().

◆ names

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

Definition at line 82 of file ApplicationDispatcher.h.

Referenced by dispatch().

◆ regex

std::regex express::dispatcher::ApplicationDispatcher::regex
private

Definition at line 81 of file ApplicationDispatcher.h.


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