From 1788749a8f808530ee3d67c42e5a35014a26780c Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 10 Dec 2024 22:51:00 +0100 Subject: [PATCH] Added a new LocaleSetupWebServerMiddleware. --- modules/web/http/web_server_middleware.cpp | 12 ++++++++++++ modules/web/http/web_server_middleware.h | 10 ++++++++++ modules/web/register_types.cpp | 4 +++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/modules/web/http/web_server_middleware.cpp b/modules/web/http/web_server_middleware.cpp index a4304ca2f..ebbe9fe30 100644 --- a/modules/web/http/web_server_middleware.cpp +++ b/modules/web/http/web_server_middleware.cpp @@ -31,6 +31,7 @@ #include "web_server_middleware.h" +#include "core/os/os.h" #include "web_server_request.h" bool WebServerMiddleware::on_before_handle_request_main(Ref request) { @@ -54,3 +55,14 @@ void WebServerMiddleware::_bind_methods() { ClassDB::bind_method(D_METHOD("_on_before_handle_request_main", "request"), &WebServerMiddleware::_on_before_handle_request_main); } + +// LocaleSetupWebServerMiddleware + +bool LocaleSetupWebServerMiddleware::_on_before_handle_request_main(Ref request) { + request->load_locale_from_cookie(); + + return false; +} + +void LocaleSetupWebServerMiddleware::_bind_methods() { +} diff --git a/modules/web/http/web_server_middleware.h b/modules/web/http/web_server_middleware.h index ffe78f1cd..edfa63ce0 100644 --- a/modules/web/http/web_server_middleware.h +++ b/modules/web/http/web_server_middleware.h @@ -54,4 +54,14 @@ protected: static void _bind_methods(); }; +class LocaleSetupWebServerMiddleware : public WebServerMiddleware { + GDCLASS(LocaleSetupWebServerMiddleware, WebServerMiddleware); + +public: + virtual bool _on_before_handle_request_main(Ref request); + +protected: + static void _bind_methods(); +}; + #endif diff --git a/modules/web/register_types.cpp b/modules/web/register_types.cpp index 5646dbcbe..036da9409 100644 --- a/modules/web/register_types.cpp +++ b/modules/web/register_types.cpp @@ -130,7 +130,6 @@ void register_web_types(ModuleRegistrationLevel p_level) { ClassDB::register_class(); - ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); @@ -143,6 +142,9 @@ void register_web_types(ModuleRegistrationLevel p_level) { ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class();