From 568bc740fed62b50519673d6eb2a2609c16d17be Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Sat, 18 Mar 2023 11:25:05 -0400 Subject: [PATCH] pass request message data to handler as well; --- network/rest/RequestDispatcher.h | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/network/rest/RequestDispatcher.h b/network/rest/RequestDispatcher.h index 449bd97f..26b36835 100644 --- a/network/rest/RequestDispatcher.h +++ b/network/rest/RequestDispatcher.h @@ -59,35 +59,35 @@ namespace network // // --------------------------------------------------------------------------- - template + template struct RequestMatcher { - typedef std::function RequestHandlerType; + typedef std::function RequestHandlerType; /// Initializes a new instance of the RequestMatcher structure. explicit RequestMatcher(const std::string& expression) : m_expression(expression), m_isRegEx(false) { /* stub */ } /// - RequestMatcher& get(RequestHandlerType handler) { + RequestMatcher& get(RequestHandlerType handler) { m_handlers["GET"] = handler; return *this; } /// - RequestMatcher& post(RequestHandlerType handler) { + RequestMatcher& post(RequestHandlerType handler) { m_handlers["POST"] = handler; return *this; } /// - RequestMatcher& put(RequestHandlerType handler) { + RequestMatcher& put(RequestHandlerType handler) { m_handlers["PUT"] = handler; return *this; } /// - RequestMatcher& del(RequestHandlerType handler) { + RequestMatcher& del(RequestHandlerType handler) { m_handlers["DELETE"] = handler; return *this; } /// - RequestMatcher& options(RequestHandlerType handler) { + RequestMatcher& options(RequestHandlerType handler) { m_handlers["OPTIONS"] = handler; return *this; } @@ -96,13 +96,12 @@ namespace network void setRegEx(bool regEx) { m_isRegEx = regEx; } /// - template void handleRequest(const Request& request, Reply& reply, const std::smatch &what) { // dispatching to matching based on handler RequestMatch match(what, request.data); auto& handler = m_handlers[request.method]; if (handler) { - handler(reply, match); + handler(request, reply, match); } } @@ -119,7 +118,7 @@ namespace network template class RequestDispatcher { - typedef RequestMatcher MatcherType; + typedef RequestMatcher MatcherType; public: /// Initializes a new instance of the RequestDispatcher class. RequestDispatcher() : m_basePath(), m_debug(false) { /* stub */ }