Added an another helper method to WebRouterNode.

This commit is contained in:
Relintai 2022-01-08 13:01:43 +01:00
parent bf7948be47
commit 7dc547b022
2 changed files with 18 additions and 0 deletions

View File

@ -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();

View File

@ -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();