Added a new RedirectWebPage WebNode.

This commit is contained in:
Relintai 2022-07-23 00:54:26 +02:00
parent 16fda02f48
commit ed92564261
5 changed files with 80 additions and 0 deletions

View File

@ -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':

View File

@ -74,6 +74,8 @@ def get_doc_classes():
"PagedArticle",
"PagedArticles",
"PagedArticlesMDIndex",
"RedirectWebPage",
]

View File

@ -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<WebServerRequest> request) {
request->send_redirect(_redirect_path, static_cast<HTTPServerEnums::HTTPStatusCode>(_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");
}

View File

@ -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<WebServerRequest> request);
RedirectWebPage();
~RedirectWebPage();
protected:
static void _bind_methods();
String _redirect_path;
int _code;
};
#endif

View File

@ -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<PagedArticle>();
ClassDB::register_class<PagedArticles>();
//ClassDB::register_class<PagedArticlesMDIndex>();
ClassDB::register_class<RedirectWebPage>();
}
void unregister_web_types() {