@@ -620,6 +620,7 @@ using Ranges = std::vector<Range>;
620620struct Request {
621621 std::string method;
622622 std::string path;
623+ const char *matched_route = nullptr ;
623624 Params params;
624625 Headers headers;
625626 std::string body;
@@ -871,10 +872,16 @@ namespace detail {
871872
872873class MatcherBase {
873874public:
875+ MatcherBase (std::string pattern) : pattern_(pattern) {}
874876 virtual ~MatcherBase () = default ;
875877
878+ const std::string &pattern () const { return pattern_; }
879+
876880 // Match request path and populate its matches and
877881 virtual bool match (Request &request) const = 0;
882+
883+ private:
884+ std::string pattern_;
878885};
879886
880887/* *
@@ -926,7 +933,8 @@ class PathParamsMatcher final : public MatcherBase {
926933 */
927934class RegexMatcher final : public MatcherBase {
928935public:
929- RegexMatcher (const std::string &pattern) : regex_(pattern) {}
936+ RegexMatcher (const std::string &pattern)
937+ : MatcherBase(pattern), regex_(pattern) {}
930938
931939 bool match (Request &request) const override ;
932940
@@ -6084,7 +6092,8 @@ inline time_t BufferStream::duration() const { return 0; }
60846092
60856093inline const std::string &BufferStream::get_buffer () const { return buffer; }
60866094
6087- inline PathParamsMatcher::PathParamsMatcher (const std::string &pattern) {
6095+ inline PathParamsMatcher::PathParamsMatcher (const std::string &pattern)
6096+ : MatcherBase(pattern) {
60886097 static constexpr char marker[] = " /:" ;
60896098
60906099 // One past the last ending position of a path param substring
@@ -6987,6 +6996,7 @@ inline bool Server::dispatch_request(Request &req, Response &res,
69876996 const auto &handler = x.second ;
69886997
69896998 if (matcher->match (req)) {
6999+ req.matched_route = matcher->pattern ().c_str ();
69907000 handler (req, res);
69917001 return true ;
69927002 }
@@ -7107,6 +7117,7 @@ inline bool Server::dispatch_request_for_content_reader(
71077117 const auto &handler = x.second ;
71087118
71097119 if (matcher->match (req)) {
7120+ req.matched_route = matcher->pattern ().c_str ();
71107121 handler (req, res, content_reader);
71117122 return true ;
71127123 }
0 commit comments