diff --git a/core/http/web_node.cpp b/core/http/web_node.cpp index 37d2f26..8fc6654 100644 --- a/core/http/web_node.cpp +++ b/core/http/web_node.cpp @@ -22,6 +22,35 @@ void WebNode::set_uri_segment(const String &val) { _uri_segment = val; } +String WebNode::get_full_uri(const bool slash_at_the_end) { + if (slash_at_the_end) { + return get_full_uri_parent(true) + _uri_segment + '/'; + } else { + return get_full_uri_parent(true) + _uri_segment; + } +} +String WebNode::get_full_uri_parent(const bool slash_at_the_end) { + String uri = "/"; + + WebNode *n = get_parent_webnode(); + + while (n) { + if (n->_uri_segment == "" || n->_uri_segment == '/') { + break; + } + + uri = "/" + n->_uri_segment + uri; + + n = n->get_parent_webnode(); + } + + if (!slash_at_the_end) { + uri.pop_back(); + } + + return uri; +} + Settings *WebNode::get_settings() { if (_settings) { return _settings; @@ -147,6 +176,10 @@ WebNode *WebNode::get_root() { return s->get_web_root(); } +WebNode *WebNode::get_parent_webnode() { + return Object::cast_to(get_parent()); +} + WebNode::WebNode() : Node() { // should look this up in parents when parented (and node parenting is implemented) diff --git a/core/http/web_node.h b/core/http/web_node.h index 20daa52..023d826 100644 --- a/core/http/web_node.h +++ b/core/http/web_node.h @@ -22,6 +22,9 @@ public: String get_uri_segment(); void set_uri_segment(const String &val); + virtual String get_full_uri(const bool slash_at_the_end = true); + virtual String get_full_uri_parent(const bool slash_at_the_end = true); + Settings *get_settings(); void set_settings(Settings *settings); @@ -50,6 +53,7 @@ public: WebServer *get_server(); WebNode *get_root(); + WebNode *get_parent_webnode(); WebNode(); ~WebNode();