Added a new LocaleSetupWebServerMiddleware.

This commit is contained in:
Relintai 2024-12-10 22:51:00 +01:00
parent 9ee96b25f8
commit 1788749a8f
3 changed files with 25 additions and 1 deletions

View File

@ -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<WebServerRequest> 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<WebServerRequest> request) {
request->load_locale_from_cookie();
return false;
}
void LocaleSetupWebServerMiddleware::_bind_methods() {
}

View File

@ -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<WebServerRequest> request);
protected:
static void _bind_methods();
};
#endif

View File

@ -130,7 +130,6 @@ void register_web_types(ModuleRegistrationLevel p_level) {
ClassDB::register_class<HTTPServerEnums>();
ClassDB::register_class<CSRFTokenWebServerMiddleware>();
ClassDB::register_class<HTTPSession>();
ClassDB::register_class<HTTPSessionManager>();
ClassDB::register_class<SessionSetupWebServerMiddleware>();
@ -143,6 +142,9 @@ void register_web_types(ModuleRegistrationLevel p_level) {
ClassDB::register_class<WebServerRequest>();
ClassDB::register_class<WebServerRequestScriptable>();
ClassDB::register_class<CSRFTokenWebServerMiddleware>();
ClassDB::register_class<LocaleSetupWebServerMiddleware>();
ClassDB::register_class<StaticWebPage>();
ClassDB::register_class<StaticWebPageFile>();
ClassDB::register_class<StaticWebPageFolderFiles>();