Added a way to get all available marameter keys to WebServerRequest.

This commit is contained in:
Relintai 2023-12-22 13:14:17 +01:00
parent e5719c991b
commit a781853b2b
6 changed files with 109 additions and 0 deletions

View File

@ -135,6 +135,41 @@ void SimpleWebServerRequest::set_header_parameter(const String &key, const Strin
_header_parameters[key] = value;
}
PoolStringArray SimpleWebServerRequest::get_header_parameter_keys() const {
PoolStringArray ks;
for (const HashMap<String, String>::Element *E = _header_parameters.front(); E; E = E->next) {
ks.push_back(E->key());
}
return ks;
}
PoolStringArray SimpleWebServerRequest::get_parameter_keys() const {
PoolStringArray g = get_get_parameter_keys();
g.append_array(get_post_parameter_keys());
return g;
}
PoolStringArray SimpleWebServerRequest::get_post_parameter_keys() const {
PoolStringArray ks;
for (const HashMap<String, String>::Element *E = _post_parameters.front(); E; E = E->next) {
ks.push_back(E->key());
}
return ks;
}
PoolStringArray SimpleWebServerRequest::get_get_parameter_keys() const {
PoolStringArray ks;
for (const HashMap<String, String>::Element *E = _get_parameters.front(); E; E = E->next) {
ks.push_back(E->key());
}
return ks;
}
void SimpleWebServerRequest::send_redirect(const String &location, const HTTPServerEnums::HTTPStatusCode status_code) {
ERR_FAIL_COND(!_server);

View File

@ -76,6 +76,11 @@ public:
virtual String get_header_parameter(const String &key) const;
virtual void set_header_parameter(const String &key, const String &value);
virtual PoolStringArray get_header_parameter_keys() const;
virtual PoolStringArray get_parameter_keys() const;
virtual PoolStringArray get_post_parameter_keys() const;
virtual PoolStringArray get_get_parameter_keys() const;
virtual void send_redirect(const String &location, const HTTPServerEnums::HTTPStatusCode status_code = HTTPServerEnums::HTTP_STATUS_CODE_302_FOUND);
virtual void send();
virtual void send_file(const String &p_file_path);

View File

@ -290,6 +290,19 @@ String WebServerRequest::get_header_parameter(const String &key) const {
void WebServerRequest::set_header_parameter(const String &key, const String &value) {
}
PoolStringArray WebServerRequest::get_header_parameter_keys() const {
return PoolStringArray();
}
PoolStringArray WebServerRequest::get_parameter_keys() const {
return PoolStringArray();
}
PoolStringArray WebServerRequest::get_post_parameter_keys() const {
return PoolStringArray();
}
PoolStringArray WebServerRequest::get_get_parameter_keys() const {
return PoolStringArray();
}
HTTPServerEnums::HTTPStatusCode WebServerRequest::get_status_code() const {
return _status_code;
}
@ -651,6 +664,11 @@ void WebServerRequest::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_header_parameter", "key"), &WebServerRequest::get_header_parameter);
ClassDB::bind_method(D_METHOD("set_header_parameter", "key", "value"), &WebServerRequest::set_header_parameter);
ClassDB::bind_method(D_METHOD("get_header_parameter_keys"), &WebServerRequest::get_header_parameter_keys);
ClassDB::bind_method(D_METHOD("get_parameter_keys"), &WebServerRequest::get_parameter_keys);
ClassDB::bind_method(D_METHOD("get_post_parameter_keys"), &WebServerRequest::get_post_parameter_keys);
ClassDB::bind_method(D_METHOD("get_get_parameter_keys"), &WebServerRequest::get_get_parameter_keys);
ClassDB::bind_method(D_METHOD("get_status_code"), &WebServerRequest::get_status_code);
ClassDB::bind_method(D_METHOD("set_status_code", "val"), &WebServerRequest::set_status_code);
ADD_PROPERTY(PropertyInfo(Variant::INT, "status_code"), "set_status_code", "get_status_code");

View File

@ -128,6 +128,11 @@ public:
virtual String get_header_parameter(const String &key) const;
virtual void set_header_parameter(const String &key, const String &value);
virtual PoolStringArray get_header_parameter_keys() const;
virtual PoolStringArray get_parameter_keys() const;
virtual PoolStringArray get_post_parameter_keys() const;
virtual PoolStringArray get_get_parameter_keys() const;
HTTPServerEnums::HTTPStatusCode get_status_code() const;
void set_status_code(const HTTPServerEnums::HTTPStatusCode status_code);

View File

@ -92,6 +92,19 @@ void WebServerRequestScriptable::set_header_parameter(const String &key, const S
call("_set_header_parameter", key, value);
}
PoolStringArray WebServerRequestScriptable::get_header_parameter_keys() const {
return const_cast<WebServerRequestScriptable *>(this)->call("_get_header_parameter_keys");
}
PoolStringArray WebServerRequestScriptable::get_parameter_keys() const {
return const_cast<WebServerRequestScriptable *>(this)->call("_get_parameter_keys");
}
PoolStringArray WebServerRequestScriptable::get_post_parameter_keys() const {
return const_cast<WebServerRequestScriptable *>(this)->call("_get_post_parameter_keys");
}
PoolStringArray WebServerRequestScriptable::get_get_parameter_keys() const {
return const_cast<WebServerRequestScriptable *>(this)->call("_get_get_parameter_keys");
}
void WebServerRequestScriptable::send_redirect(const String &location, const HTTPServerEnums::HTTPStatusCode status_code) {
call("_send_redirect", location, status_code);
}
@ -186,6 +199,19 @@ String WebServerRequestScriptable::_get_header_parameter(const String &key) cons
void WebServerRequestScriptable::_set_header_parameter(const String &key, const String &value) {
}
PoolStringArray WebServerRequestScriptable::_get_header_parameter_keys() const {
return PoolStringArray();
}
PoolStringArray WebServerRequestScriptable::_get_parameter_keys() const {
return PoolStringArray();
}
PoolStringArray WebServerRequestScriptable::_get_post_parameter_keys() const {
return PoolStringArray();
}
PoolStringArray WebServerRequestScriptable::_get_get_parameter_keys() const {
return PoolStringArray();
}
void WebServerRequestScriptable::_send_redirect(const String &location, const HTTPServerEnums::HTTPStatusCode status_code) {
}
@ -287,6 +313,11 @@ void WebServerRequestScriptable::_bind_methods() {
BIND_VMETHOD(MethodInfo("_get_header_parameter", PropertyInfo(Variant::STRING, "key")));
BIND_VMETHOD(MethodInfo("_set_header_parameter", PropertyInfo(Variant::STRING, "key"), PropertyInfo(Variant::STRING, "value")));
BIND_VMETHOD(MethodInfo(Variant::POOL_STRING_ARRAY, "_get_header_parameter_keys"));
BIND_VMETHOD(MethodInfo(Variant::POOL_STRING_ARRAY, "_get_parameter_keys"));
BIND_VMETHOD(MethodInfo(Variant::POOL_STRING_ARRAY, "_get_post_parameter_keys"));
BIND_VMETHOD(MethodInfo(Variant::POOL_STRING_ARRAY, "_get_get_parameter_keys"));
BIND_VMETHOD(MethodInfo("_send_redirect", PropertyInfo(Variant::STRING, "location"), PropertyInfo(Variant::INT, "status_code")));
BIND_VMETHOD(MethodInfo("_compile_body"));
@ -323,6 +354,11 @@ void WebServerRequestScriptable::_bind_methods() {
ClassDB::bind_method(D_METHOD("_get_header_parameter", "key"), &WebServerRequestScriptable::_get_header_parameter);
ClassDB::bind_method(D_METHOD("_set_header_parameter", "key", "value"), &WebServerRequestScriptable::_set_header_parameter);
ClassDB::bind_method(D_METHOD("_get_header_parameter_keys"), &WebServerRequestScriptable::_get_header_parameter_keys);
ClassDB::bind_method(D_METHOD("_get_parameter_keys"), &WebServerRequestScriptable::_get_parameter_keys);
ClassDB::bind_method(D_METHOD("_get_post_parameter_keys"), &WebServerRequestScriptable::_get_post_parameter_keys);
ClassDB::bind_method(D_METHOD("_get_get_parameter_keys"), &WebServerRequestScriptable::_get_get_parameter_keys);
ClassDB::bind_method(D_METHOD("_send_redirect", "location", "status_code"), &WebServerRequestScriptable::_send_redirect);
ClassDB::bind_method(D_METHOD("_compile_body"), &WebServerRequestScriptable::_compile_body);

View File

@ -75,6 +75,11 @@ public:
virtual String get_header_parameter(const String &key) const;
virtual void set_header_parameter(const String &key, const String &value);
virtual PoolStringArray get_header_parameter_keys() const;
virtual PoolStringArray get_parameter_keys() const;
virtual PoolStringArray get_post_parameter_keys() const;
virtual PoolStringArray get_get_parameter_keys() const;
virtual void send_redirect(const String &location, const HTTPServerEnums::HTTPStatusCode status_code = HTTPServerEnums::HTTP_STATUS_CODE_302_FOUND);
virtual void compile_body();
virtual void compile_and_send_body();
@ -111,6 +116,11 @@ public:
virtual String _get_header_parameter(const String &key) const;
virtual void _set_header_parameter(const String &key, const String &value);
virtual PoolStringArray _get_header_parameter_keys() const;
virtual PoolStringArray _get_parameter_keys() const;
virtual PoolStringArray _get_post_parameter_keys() const;
virtual PoolStringArray _get_get_parameter_keys() const;
void _send_redirect(const String &location, const HTTPServerEnums::HTTPStatusCode status_code);
void _compile_body();
void _compile_and_send_body();