Skip to content

Commit

Permalink
Added a new LocaleSetupWebServerMiddleware.
Browse files Browse the repository at this point in the history
  • Loading branch information
Relintai committed Dec 10, 2024
1 parent 9ee96b2 commit 1788749
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
12 changes: 12 additions & 0 deletions modules/web/http/web_server_middleware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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() {
}
10 changes: 10 additions & 0 deletions modules/web/http/web_server_middleware.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,14 @@ class WebServerMiddleware : public Resource {
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
4 changes: 3 additions & 1 deletion modules/web/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand All @@ -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>();
Expand Down

0 comments on commit 1788749

Please sign in to comment.