More cleanups to the csrf token middleware.

This commit is contained in:
Relintai 2022-06-26 20:54:26 +02:00
parent c3458b80bc
commit 47ee34044a
2 changed files with 17 additions and 2 deletions

View File

@ -6,6 +6,13 @@
#include "http_session.h"
#include "web_server_request.h"
PoolStringArray CSRFTokenWebServerMiddleware::get_ignored_urls() {
return ignored_urls;
}
void CSRFTokenWebServerMiddleware::set_ignored_urls(const PoolStringArray &val) {
ignored_urls = val;
}
bool CSRFTokenWebServerMiddleware::_on_before_handle_request_main(Ref<WebServerRequest> request) {
switch (request->get_method()) {
case HTTPServerEnums::HTTP_METHOD_POST:
@ -68,4 +75,9 @@ CSRFTokenWebServerMiddleware::~CSRFTokenWebServerMiddleware() {
}
void CSRFTokenWebServerMiddleware::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_ignored_urls"), &CSRFTokenWebServerMiddleware::get_ignored_urls);
ClassDB::bind_method(D_METHOD("set_ignored_urls", "val"), &CSRFTokenWebServerMiddleware::set_ignored_urls);
ADD_PROPERTY(PropertyInfo(Variant::POOL_STRING_ARRAY, "ignored_urls"), "set_ignored_urls", "get_ignored_urls");
ClassDB::bind_method(D_METHOD("create_token"), &CSRFTokenWebServerMiddleware::create_token);
}

View File

@ -4,7 +4,7 @@
#include "web_server_middleware.h"
#include "core/ustring.h"
#include "core/vector.h"
#include "core/variant.h"
class WebServerRequest;
@ -12,6 +12,9 @@ class CSRFTokenWebServerMiddleware : public WebServerMiddleware {
GDCLASS(CSRFTokenWebServerMiddleware, WebServerMiddleware);
public:
PoolStringArray get_ignored_urls();
void set_ignored_urls(const PoolStringArray &val);
//returnring true means handled, false means continue
bool _on_before_handle_request_main(Ref<WebServerRequest> request);
@ -22,7 +25,7 @@ public:
CSRFTokenWebServerMiddleware();
~CSRFTokenWebServerMiddleware();
Vector<String> ignored_urls;
PoolStringArray ignored_urls;
protected:
static void _bind_methods();