From 7dc547b022f081470a22e78edb4dd1d49d230ea2 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 8 Jan 2022 13:01:43 +0100 Subject: [PATCH] Added an another helper method to WebRouterNode. --- core/http/web_router_node.cpp | 17 +++++++++++++++++ core/http/web_router_node.h | 1 + 2 files changed, 18 insertions(+) diff --git a/core/http/web_router_node.cpp b/core/http/web_router_node.cpp index ee392de..8548965 100644 --- a/core/http/web_router_node.cpp +++ b/core/http/web_router_node.cpp @@ -33,6 +33,23 @@ bool WebRouterNode::try_route_request_to_children(Request *request) { return true; } +WebNode *WebRouterNode::get_request_handler_child(Request *request) { + WebNode *handler = nullptr; + + // if (path == "/") { + if (request->get_path_segment_count() == 0) { + // quick shortcut + handler = _index_node; + } else { + const String &main_route = request->get_current_path_segment(); + handler = _node_route_map[main_route]; + + request->push_path(); + } + + return handler; +} + void WebRouterNode::build_handler_map() { _index_node = nullptr; _node_route_map.clear(); diff --git a/core/http/web_router_node.h b/core/http/web_router_node.h index 9af3546..c61c1be 100644 --- a/core/http/web_router_node.h +++ b/core/http/web_router_node.h @@ -12,6 +12,7 @@ class WebRouterNode : public WebNode { public: void handle_request_main(Request *request); bool try_route_request_to_children(Request *request); + WebNode *get_request_handler_child(Request *request); void build_handler_map();