diff --git a/modules/web/SCsub b/modules/web/SCsub index 8d06037d5..9d833bd1d 100644 --- a/modules/web/SCsub +++ b/modules/web/SCsub @@ -59,6 +59,8 @@ sources = [ "nodes/paged_article/paged_article.cpp", "nodes/paged_article/paged_articles.cpp", #"nodes/paged_article/paged_articles_md_index.cpp", + + "nodes/redirect/redirect_web_page.cpp", ] if ARGUMENTS.get('custom_modules_shared', 'no') == 'yes': diff --git a/modules/web/config.py b/modules/web/config.py index f514f5a6a..afb17fc2c 100644 --- a/modules/web/config.py +++ b/modules/web/config.py @@ -74,6 +74,8 @@ def get_doc_classes(): "PagedArticle", "PagedArticles", "PagedArticlesMDIndex", + + "RedirectWebPage", ] diff --git a/modules/web/nodes/redirect/redirect_web_page.cpp b/modules/web/nodes/redirect/redirect_web_page.cpp new file mode 100644 index 000000000..bab1a06d4 --- /dev/null +++ b/modules/web/nodes/redirect/redirect_web_page.cpp @@ -0,0 +1,40 @@ +#include "redirect_web_page.h" + +#include "../../http/http_server_enums.h" +#include "../../http/web_server_request.h" +#include "core/os/file_access.h" + +String RedirectWebPage::get_redirect_path() { + return _redirect_path; +} +void RedirectWebPage::set_redirect_path(const String &val) { + _redirect_path = val; +} + +int RedirectWebPage::get_code() { + return _code; +} +void RedirectWebPage::set_code(const int val) { + _code = val; +} + +void RedirectWebPage::_handle_request(Ref request) { + request->send_redirect(_redirect_path, static_cast(_code)); +} + +RedirectWebPage::RedirectWebPage() { + _code = 302; +} + +RedirectWebPage::~RedirectWebPage() { +} + +void RedirectWebPage::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_redirect_path"), &RedirectWebPage::get_redirect_path); + ClassDB::bind_method(D_METHOD("set_redirect_path", "val"), &RedirectWebPage::set_redirect_path); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "redirect_path"), "set_redirect_path", "get_redirect_path"); + + ClassDB::bind_method(D_METHOD("get_code"), &RedirectWebPage::get_code); + ClassDB::bind_method(D_METHOD("set_code", "val"), &RedirectWebPage::set_code); + ADD_PROPERTY(PropertyInfo(Variant::INT, "code"), "set_code", "get_code"); +} diff --git a/modules/web/nodes/redirect/redirect_web_page.h b/modules/web/nodes/redirect/redirect_web_page.h new file mode 100644 index 000000000..83a900f31 --- /dev/null +++ b/modules/web/nodes/redirect/redirect_web_page.h @@ -0,0 +1,32 @@ +#ifndef REDIRECT_WEB_PAGE_H +#define REDIRECT_WEB_PAGE_H + +#include "core/ustring.h" + +#include "../../http/web_node.h" + +class WebServerRequest; + +class RedirectWebPage : public WebNode { + GDCLASS(RedirectWebPage, WebNode); + +public: + String get_redirect_path(); + void set_redirect_path(const String &val); + + int get_code(); + void set_code(const int val); + + void _handle_request(Ref request); + + RedirectWebPage(); + ~RedirectWebPage(); + +protected: + static void _bind_methods(); + + String _redirect_path; + int _code; +}; + +#endif diff --git a/modules/web/register_types.cpp b/modules/web/register_types.cpp index 35695a6f0..1da8b43a3 100644 --- a/modules/web/register_types.cpp +++ b/modules/web/register_types.cpp @@ -60,6 +60,8 @@ SOFTWARE. #include "nodes/paged_article/paged_articles.h" //#include "nodes/paged_article/paged_articles_md_index.h" +#include "nodes/redirect/redirect_web_page.h" + void register_web_types() { ClassDB::register_class<_HTMLBuilder>(); ClassDB::register_class<_HTMLTag>(); @@ -122,6 +124,8 @@ void register_web_types() { ClassDB::register_class(); ClassDB::register_class(); //ClassDB::register_class(); + + ClassDB::register_class(); } void unregister_web_types() {