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 62 of file ApplicationDispatcher.cpp.

64 : lambda(lambda) {
65 }
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 67 of file ApplicationDispatcher.cpp.

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

134 {
135 std::list<std::string> routes{"A " + parentMountPath + mountPoint.relativeMountPath + (!strictRouting ? "*" : "")};
136 routes.push_back(" " + mountPoint.method + " " + mountPoint.relativeMountPath);
137
138 if (nextRoute) {
139 routes.splice(routes.end(), nextRoute->getRoute(parentMountPath, strictRouting));
140 }
141
142 return routes;
143 }
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: