Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
mana::Server::process implementation
void Server::process(Request_ptr req, Response_ptr res) {
auto it_ptr = std::make_shared<MiddlewareStack::iterator>(middleware_.begin());
auto next = std::make_shared<next_t>();
auto weak_next = std::weak_ptr<next_t>(next);
// setup Next callback
*next = [this, it_ptr, weak_next, req, res]
// derefence the pointer to the iterator
auto& it = *it_ptr;
// skip those who don't match
while(it != middleware_.end() and !path_starts_with(req->uri().path(), it->path))
// while there is more to do
if(it != middleware_.end()) {
// dereference the function
auto& func = it->callback;
// advance the iterator for the next next-call
auto next = weak_next.lock(); // this should be safe since we're inside next
// execute the function
func(req, res, next);
// no more middleware, proceed with route processing
else {
process_route(req, res);
// get the party started..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.