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

#include <MiddlewareDispatcher.h>

Inheritance diagram for express::dispatcher::MiddlewareDispatcher:
Collaboration diagram for express::dispatcher::MiddlewareDispatcher:

Public Member Functions

 MiddlewareDispatcher (const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &, express::Next &)> &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
 

Private Attributes

const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &, express::Next &)> lambda
 

Detailed Description

Definition at line 41 of file MiddlewareDispatcher.h.

Constructor & Destructor Documentation

◆ MiddlewareDispatcher()

express::dispatcher::MiddlewareDispatcher::MiddlewareDispatcher ( const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &, express::Next &)> & lambda)
explicit

Definition at line 33 of file MiddlewareDispatcher.cpp.

35 : lambda(lambda) {
36 }
const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &, express::Next &)> lambda

References MiddlewareDispatcher().

Referenced by MiddlewareDispatcher().

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

Member Function Documentation

◆ dispatch()

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

Implements express::Dispatcher.

Definition at line 38 of file MiddlewareDispatcher.cpp.

38 {
39 bool dispatched = false;
40
41 if ((controller.getFlags() & Controller::NEXT) == 0) {
42 const std::string absoluteMountPath = path_concat(parentMountPath, mountPoint.relativeMountPath);
43
44 if (((controller.getRequest()->path.rfind(absoluteMountPath, 0) == 0 ||
45 controller.getRequest()->url.rfind(absoluteMountPath, 0) == 0) &&
46 mountPoint.method == "use") ||
47 ((absoluteMountPath == controller.getRequest()->url || absoluteMountPath == controller.getRequest()->path ||
48 checkForUrlMatch(absoluteMountPath, controller.getRequest()->url)) &&
49 (controller.getRequest()->method == mountPoint.method || mountPoint.method == "all"))) {
50 dispatched = true;
51
52 if (hasResult(absoluteMountPath)) {
53 setParams(absoluteMountPath, *controller.getRequest());
54 }
55
56 Next next(controller);
57 lambda(controller.getRequest(), controller.getResponse(), next);
58
59 // If next() was called synchronously continue current route-tree traversal
60 if ((next.controller.getFlags() & express::Controller::NEXT) != 0) {
61 dispatched = false;
62 controller = next.controller;
63 }
64 }
65 }
66
67 return dispatched;
68 }
const std::shared_ptr< Request > & getRequest()
int getFlags() const
const std::shared_ptr< Response > & getResponse()
bool checkForUrlMatch(const std::string &cpath, const std::string &reqpath)
void setParams(const std::string &cpath, express::Request &req)
bool hasResult(const std::string &cpath)
std::string path_concat(const std::vector< std::string > &stringvec)
std::string method
Definition MountPoint.h:34
std::string relativeMountPath
Definition MountPoint.h:35

References express::Controller::getFlags(), express::Controller::NEXT, and express::Next::Next().

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::Next&)> express::dispatcher::MiddlewareDispatcher::lambda
private

Definition at line 49 of file MiddlewareDispatcher.h.


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