2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
42#include "express/dispatcher/ApplicationDispatcher.h"
44#include "core/socket/stream/SocketConnection.h"
45#include "express/Controller.h"
46#include "express/Request.h"
47#include "express/Response.h"
48#include "express/Route.h"
49#include "express/dispatcher/regex_utils.h"
50#include "web/http/server/SocketContext.h"
52#ifndef DOXYGEN_SHOULD_SKIP_THIS
54#include "log/Logger.h"
59#include <unordered_map>
66 const std::function<
void(
const std::shared_ptr<
Request>&,
const std::shared_ptr<
Response>&)>& lambda)
71 const std::string& parentMountPath,
73 bool requestMatched =
false;
79 std::string_view mountPath;
80 std::string_view mountQueryString;
84 std::string_view requestPath;
85 std::string_view requestQueryString;
90 std::string_view normalizedMountPath = mountPath;
91 std::string_view normalizedRequestPath = requestPath;
96 if (normalizedMountPath.empty()) {
97 normalizedMountPath =
"/";
100 bool pathMatches =
false;
101 if (mountPath.find(
':') != std::string::npos) {
102 if (regex.mark_count() == 0) {
103 LOG(TRACE) <<
"ApplicationDispatcher: precompiled regex";
109 LOG(TRACE) <<
"ApplicationDispatcher: using precompiled regex";
117 requestMatched = (pathMatches && queryMatches);
120 <<
" HTTP Express: application -> " << (requestMatched ?
"MATCH" :
"NO MATCH");
124 LOG(TRACE) <<
" AbsoluteMountPath: " << absoluteMountPath;
128 if (requestMatched) {
139 <<
" HTTP Express: application -> next(...) called";
143 LOG(TRACE) <<
" AbsoluteMountPath: " << absoluteMountPath;
146 return requestMatched;
149 std::list<std::string>
151 std::list<std::string> routes{
"A " + parentMountPath + mountPoint
.relativeMountPath + (!strictRouting ?
"*" :
"")};
const std::string & getConnectionName() const
SocketConnection * getSocketConnection() const
const std::shared_ptr< Request > & getRequest()
bool getStrictRouting() const
bool getCaseInsensitiveRouting() const
const std::shared_ptr< Response > & getResponse()
std::shared_ptr< Route > nextRoute
web::http::CiStringMap< std::string > queries
web::http::server::SocketContext * getSocketContext() const
std::list< std::string > getRoute(const std::string &parentMountPath, bool strictRouting) const
std::vector< std::string > names
const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> lambda
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
ApplicationDispatcher(const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &lambda)
bool matchAndFillParams(const std::regex &rx, const std::vector< std::string > &names, std::string_view reqPath, RequestLike &req)
bool querySupersetMatches(const std::unordered_map< std::string, std::string > &rq, const std::unordered_map< std::string, std::string > &need)
void setParams(const std::string &cpath, Request &req)
void splitPathAndQuery(std::string_view url, std::string_view &path, std::string_view &query)
std::pair< std::regex, std::vector< std::string > > compileParamRegex(std::string_view mountPath, bool isPrefix, bool strictRouting, bool caseInsensitive)
std::unordered_map< std::string, std::string > parseQuery(std::string_view qs)
bool hasResult(const std::string &cpath)
std::string_view trimOneTrailingSlash(std::string_view s)
bool equalPath(std::string_view a, std::string_view b, bool caseInsensitive)
std::string relativeMountPath