@@ -620,6 +620,7 @@ using Ranges = std::vector<Range>;
620
620
struct Request {
621
621
std::string method;
622
622
std::string path;
623
+ const char *matched_route = nullptr ;
623
624
Params params;
624
625
Headers headers;
625
626
std::string body;
@@ -871,10 +872,16 @@ namespace detail {
871
872
872
873
class MatcherBase {
873
874
public:
875
+ MatcherBase (std::string pattern) : pattern_(pattern) {}
874
876
virtual ~MatcherBase () = default ;
875
877
878
+ const std::string &pattern () const { return pattern_; }
879
+
876
880
// Match request path and populate its matches and
877
881
virtual bool match (Request &request) const = 0;
882
+
883
+ private:
884
+ std::string pattern_;
878
885
};
879
886
880
887
/* *
@@ -926,7 +933,8 @@ class PathParamsMatcher final : public MatcherBase {
926
933
*/
927
934
class RegexMatcher final : public MatcherBase {
928
935
public:
929
- RegexMatcher(const std::string &pattern) : regex_(pattern) {}
936
+ RegexMatcher (const std::string &pattern)
937
+ : MatcherBase(pattern), regex_(pattern) {}
930
938
931
939
bool match (Request &request) const override ;
932
940
@@ -6084,7 +6092,8 @@ inline time_t BufferStream::duration() const { return 0; }
6084
6092
6085
6093
inline const std::string &BufferStream::get_buffer () const { return buffer; }
6086
6094
6087
- inline PathParamsMatcher::PathParamsMatcher(const std::string &pattern) {
6095
+ inline PathParamsMatcher::PathParamsMatcher (const std::string &pattern)
6096
+ : MatcherBase(pattern) {
6088
6097
static constexpr char marker[] = " /:" ;
6089
6098
6090
6099
// One past the last ending position of a path param substring
@@ -6987,6 +6996,7 @@ inline bool Server::dispatch_request(Request &req, Response &res,
6987
6996
const auto &handler = x.second ;
6988
6997
6989
6998
if (matcher->match (req)) {
6999
+ req.matched_route = matcher->pattern ().c_str ();
6990
7000
handler (req, res);
6991
7001
return true ;
6992
7002
}
@@ -7107,6 +7117,7 @@ inline bool Server::dispatch_request_for_content_reader(
7107
7117
const auto &handler = x.second ;
7108
7118
7109
7119
if (matcher->match (req)) {
7120
+ req.matched_route = matcher->pattern ().c_str ();
7110
7121
handler (req, res, content_reader);
7111
7122
return true ;
7112
7123
}
0 commit comments