2022-06-26 11:07:45 +02:00
|
|
|
#ifndef WEB_SERVER_REQUEST_H
|
|
|
|
#define WEB_SERVER_REQUEST_H
|
2022-06-25 01:55:54 +02:00
|
|
|
|
2023-12-18 00:25:33 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* web_server_request.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* PANDEMONIUM ENGINE */
|
|
|
|
/* https://github.com/Relintai/pandemonium_engine */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* Copyright (c) 2022-present Péter Magyar. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2023-07-08 21:11:56 +02:00
|
|
|
#include "core/containers/hash_map.h"
|
2023-12-18 00:25:33 +01:00
|
|
|
#include "core/containers/vector.h"
|
|
|
|
#include "core/string/ustring.h"
|
|
|
|
#include "core/variant/dictionary.h"
|
2022-06-25 01:55:54 +02:00
|
|
|
|
2022-08-17 13:45:14 +02:00
|
|
|
#include "core/object/object.h"
|
|
|
|
#include "core/object/reference.h"
|
2022-06-25 01:55:54 +02:00
|
|
|
|
2022-06-26 17:23:40 +02:00
|
|
|
#include "http_server_enums.h"
|
2022-06-25 01:55:54 +02:00
|
|
|
|
|
|
|
class WebServer;
|
2022-06-26 15:00:25 +02:00
|
|
|
class WebServerCookie;
|
2022-06-25 01:55:54 +02:00
|
|
|
class HTTPSession;
|
|
|
|
class WebPermission;
|
2022-06-27 14:16:23 +02:00
|
|
|
class WebNode;
|
2022-06-25 01:55:54 +02:00
|
|
|
|
2022-06-26 15:00:25 +02:00
|
|
|
class WebServerRequest : public Reference {
|
|
|
|
GDCLASS(WebServerRequest, Reference);
|
|
|
|
|
2022-06-25 01:55:54 +02:00
|
|
|
public:
|
2022-06-26 19:25:57 +02:00
|
|
|
String get_head();
|
|
|
|
void set_head(const String &val);
|
2022-06-25 01:55:54 +02:00
|
|
|
|
2022-06-26 19:25:57 +02:00
|
|
|
String get_body();
|
|
|
|
void set_body(const String &val);
|
2022-06-25 01:55:54 +02:00
|
|
|
|
2022-06-26 19:25:57 +02:00
|
|
|
String get_footer();
|
|
|
|
void set_footer(const String &val);
|
2022-06-25 01:55:54 +02:00
|
|
|
|
2022-06-26 19:25:57 +02:00
|
|
|
String get_compiled_body();
|
|
|
|
void set_compiled_body(const String &val);
|
2022-06-25 01:55:54 +02:00
|
|
|
|
2022-06-26 19:25:57 +02:00
|
|
|
bool get_connection_closed();
|
|
|
|
void set_connection_closed(const bool &val);
|
2022-06-25 01:55:54 +02:00
|
|
|
|
2022-06-26 19:25:57 +02:00
|
|
|
Ref<HTTPSession> get_session();
|
|
|
|
void set_session(const Ref<HTTPSession> &val);
|
2022-06-25 01:55:54 +02:00
|
|
|
|
2022-06-26 19:25:57 +02:00
|
|
|
Dictionary get_data();
|
|
|
|
void set_data(const Dictionary &val);
|
|
|
|
|
|
|
|
Ref<WebPermission> get_active_permission();
|
|
|
|
void set_active_permission(const Ref<WebPermission> &val);
|
|
|
|
|
|
|
|
int get_permissions();
|
|
|
|
void set_permissions(const int &val);
|
|
|
|
|
|
|
|
Ref<HTTPSession> get_or_create_session();
|
2022-06-25 01:55:54 +02:00
|
|
|
|
|
|
|
bool can_view() const;
|
|
|
|
bool can_create() const;
|
|
|
|
bool can_edit() const;
|
|
|
|
bool can_delete() const;
|
|
|
|
|
|
|
|
bool has_csrf_token();
|
|
|
|
String get_csrf_token();
|
|
|
|
void set_csrf_token(const String &value);
|
|
|
|
bool validate_csrf_token();
|
|
|
|
|
2022-06-27 14:23:07 +02:00
|
|
|
virtual String get_cookie(const String &key);
|
2022-07-21 14:05:55 +02:00
|
|
|
|
|
|
|
void response_add_cookie(const Ref<WebServerCookie> &cookie);
|
|
|
|
int response_get_cookie_count();
|
|
|
|
Ref<WebServerCookie> response_get_cookie(const int index);
|
|
|
|
void response_remove_cookie(const int index);
|
|
|
|
void response_remove_cookie_simple(const String &key);
|
2022-06-25 01:55:54 +02:00
|
|
|
|
2023-12-18 00:25:33 +01:00
|
|
|
void custom_response_header_set(const StringName &key, const String &value);
|
2023-07-08 21:11:56 +02:00
|
|
|
String custom_response_header_get(const StringName &key);
|
|
|
|
bool custom_response_header_has(const StringName &key);
|
|
|
|
HashMap<StringName, String> custom_response_headers_get();
|
|
|
|
Dictionary custom_response_headers_get_bind();
|
|
|
|
|
|
|
|
String get_content_type();
|
|
|
|
void set_content_type(const String &content_type);
|
|
|
|
|
2022-06-26 19:25:57 +02:00
|
|
|
virtual HTTPServerEnums::HTTPMethod get_method() const;
|
2022-06-25 01:55:54 +02:00
|
|
|
|
|
|
|
virtual void parse_files();
|
|
|
|
virtual int get_file_count() const;
|
2022-07-20 21:29:59 +02:00
|
|
|
virtual String get_file_file_name(const int index) const;
|
|
|
|
virtual String get_file_key(const int index) const;
|
2022-06-25 01:55:54 +02:00
|
|
|
virtual int get_file_length(const int index) const;
|
2022-07-20 22:53:55 +02:00
|
|
|
virtual PoolByteArray get_file_data(const int index) const;
|
2022-06-27 14:23:07 +02:00
|
|
|
virtual String get_file_data_str(const int index) const;
|
2022-06-25 01:55:54 +02:00
|
|
|
|
2022-06-27 14:23:07 +02:00
|
|
|
virtual String get_parameter(const String &key) const;
|
2022-12-21 14:52:11 +01:00
|
|
|
virtual String get_post_parameter(const String &key) const;
|
|
|
|
virtual String get_get_parameter(const String &key) const;
|
2022-06-25 01:55:54 +02:00
|
|
|
|
2023-03-22 13:20:25 +01:00
|
|
|
virtual void set_post_parameter(const String &key, const String &value);
|
|
|
|
virtual void set_get_parameter(const String &key, const String &value);
|
|
|
|
|
2023-12-22 13:02:17 +01:00
|
|
|
virtual String get_header_parameter(const String &key) const;
|
|
|
|
virtual void set_header_parameter(const String &key, const String &value);
|
|
|
|
|
2022-06-26 19:25:57 +02:00
|
|
|
HTTPServerEnums::HTTPStatusCode get_status_code() const;
|
|
|
|
void set_status_code(const HTTPServerEnums::HTTPStatusCode status_code);
|
2022-06-25 01:55:54 +02:00
|
|
|
|
2022-06-26 19:25:57 +02:00
|
|
|
virtual void send_redirect(const String &location, const HTTPServerEnums::HTTPStatusCode status_code = HTTPServerEnums::HTTP_STATUS_CODE_302_FOUND);
|
2022-06-25 01:55:54 +02:00
|
|
|
virtual void compile_body();
|
|
|
|
virtual void compile_and_send_body();
|
|
|
|
virtual void send();
|
|
|
|
virtual void send_file(const String &p_file_path);
|
|
|
|
virtual void send_error(int error_code);
|
|
|
|
virtual String parser_get_path();
|
|
|
|
virtual String get_host() const;
|
|
|
|
|
|
|
|
void setup_url_stack();
|
|
|
|
String get_path(const bool beginning_slash = false, const bool end_slash = true) const;
|
2022-06-26 19:25:57 +02:00
|
|
|
virtual String get_path_full() const;
|
|
|
|
String get_path_segment(const uint32_t i) const;
|
|
|
|
String get_current_path_segment() const;
|
|
|
|
String get_next_path_segment() const;
|
2022-06-25 01:55:54 +02:00
|
|
|
uint32_t get_path_segment_count() const;
|
|
|
|
uint32_t get_current_segment_index() const;
|
|
|
|
uint32_t get_remaining_segment_count() const;
|
|
|
|
void pop_path();
|
|
|
|
void push_path();
|
|
|
|
|
|
|
|
String get_url_root_parent(const int parent = 1) const;
|
|
|
|
String get_url_root() const;
|
|
|
|
String get_url_root_current() const;
|
|
|
|
String get_url_site() const;
|
|
|
|
|
2022-06-26 19:25:57 +02:00
|
|
|
String get_url_root_parent_add(const String &add) const;
|
|
|
|
String get_url_root_add(const String &add) const;
|
2023-03-22 13:22:32 +01:00
|
|
|
String get_url_root_current_add(const String &add) const;
|
2022-06-26 19:25:57 +02:00
|
|
|
String get_url_site_add(const String &add) const;
|
2022-06-25 01:55:54 +02:00
|
|
|
|
|
|
|
virtual void update();
|
2022-06-26 19:25:57 +02:00
|
|
|
|
|
|
|
WebServer *get_server();
|
2022-06-27 14:16:23 +02:00
|
|
|
WebNode *get_web_root();
|
2022-06-25 01:55:54 +02:00
|
|
|
|
2022-06-26 11:07:45 +02:00
|
|
|
WebServerRequest();
|
2022-06-26 19:25:57 +02:00
|
|
|
~WebServerRequest();
|
|
|
|
|
|
|
|
String head;
|
|
|
|
String body;
|
|
|
|
String footer;
|
|
|
|
String compiled_body;
|
|
|
|
|
2022-07-21 23:25:04 +02:00
|
|
|
void _set_server(WebServer *v);
|
|
|
|
void _set_web_root(WebNode *v);
|
2022-06-25 01:55:54 +02:00
|
|
|
|
|
|
|
protected:
|
2022-06-26 19:25:57 +02:00
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
HTTPServerEnums::HTTPStatusCode _status_code;
|
2022-06-25 01:55:54 +02:00
|
|
|
String _full_path;
|
|
|
|
Vector<String> _path_stack;
|
2022-06-27 16:06:26 +02:00
|
|
|
int _path_stack_pointer;
|
2022-07-21 14:05:55 +02:00
|
|
|
Vector<Ref<WebServerCookie>> _cookies;
|
2022-07-21 23:25:04 +02:00
|
|
|
|
2023-07-08 21:11:56 +02:00
|
|
|
HashMap<StringName, String> _custom_response_headers;
|
|
|
|
|
2022-07-21 23:25:04 +02:00
|
|
|
Ref<WebPermission> _active_permission;
|
|
|
|
int _permissions;
|
|
|
|
|
|
|
|
Ref<HTTPSession> _session;
|
|
|
|
|
|
|
|
bool _connection_closed;
|
|
|
|
|
|
|
|
WebServer *_server;
|
|
|
|
WebNode *_web_root;
|
2022-06-25 01:55:54 +02:00
|
|
|
};
|
|
|
|
|
2022-06-26 03:37:36 +02:00
|
|
|
#endif
|