2022-06-30 18:06:02 +02:00
|
|
|
#ifndef SIMPLE_WEB_SERVER_REQUEST_H
|
|
|
|
#define SIMPLE_WEB_SERVER_REQUEST_H
|
|
|
|
|
2023-12-18 00:02:58 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* simple_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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2022-08-17 12:53:49 +02:00
|
|
|
#include "core/containers/hash_map.h"
|
|
|
|
#include "core/containers/vector.h"
|
2023-12-18 00:02:58 +01:00
|
|
|
#include "core/os/file_access.h"
|
2022-12-21 14:52:11 +01:00
|
|
|
#include "core/string/ustring.h"
|
|
|
|
#include "core/variant/dictionary.h"
|
2022-06-30 18:06:02 +02:00
|
|
|
|
2022-08-19 22:09:30 +02:00
|
|
|
#include "modules/web/http/web_server_request.h"
|
2022-06-30 18:06:02 +02:00
|
|
|
|
2022-08-19 22:09:30 +02:00
|
|
|
#include "modules/web/http/http_server_enums.h"
|
2022-06-30 18:06:02 +02:00
|
|
|
|
|
|
|
class WebServer;
|
|
|
|
class WebServerCookie;
|
|
|
|
class HTTPSession;
|
|
|
|
class WebPermission;
|
|
|
|
class WebNode;
|
2022-07-01 17:40:47 +02:00
|
|
|
class HTTPServerSimple;
|
2022-07-24 02:40:39 +02:00
|
|
|
class HTTPServerConnection;
|
2022-06-30 18:06:02 +02:00
|
|
|
|
|
|
|
class SimpleWebServerRequest : public WebServerRequest {
|
|
|
|
GDCLASS(SimpleWebServerRequest, WebServerRequest);
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual String get_cookie(const String &key);
|
|
|
|
|
|
|
|
virtual HTTPServerEnums::HTTPMethod get_method() const;
|
|
|
|
|
|
|
|
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;
|
2024-03-09 23:39:33 +01:00
|
|
|
virtual uint64_t 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-30 18:06:02 +02:00
|
|
|
virtual String get_file_data_str(const int index) const;
|
2024-03-09 23:39:33 +01:00
|
|
|
virtual Error move_file(const int index, const String &p_dest_file);
|
|
|
|
virtual bool is_file_moved(const int index) const;
|
2022-06-30 18:06:02 +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-30 18:06:02 +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);
|
|
|
|
|
2023-12-22 13:14:17 +01:00
|
|
|
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;
|
|
|
|
|
2022-06-30 18:06:02 +02:00
|
|
|
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);
|
|
|
|
virtual String parser_get_path();
|
|
|
|
virtual String get_host() const;
|
|
|
|
|
2022-12-21 14:52:11 +01:00
|
|
|
void add_post_parameter(const String &key, const String &value);
|
|
|
|
void add_get_parameter(const String &key, const String &value);
|
2023-12-22 13:02:17 +01:00
|
|
|
void add_header_parameter(const String &key, const String &value);
|
2022-07-01 17:40:47 +02:00
|
|
|
void set_parser_path(const String &value);
|
|
|
|
void set_host(const String &value);
|
|
|
|
|
2024-03-09 23:39:33 +01:00
|
|
|
void add_file_memory(const String &key, const String &file_name, const PoolByteArray &data);
|
|
|
|
void add_file_temp_file(const String &key, const String &file_name, const String &path);
|
2022-07-20 21:29:59 +02:00
|
|
|
|
2022-07-21 15:51:44 +02:00
|
|
|
void add_cookie_data(const String &key, const String &value);
|
|
|
|
|
2022-07-21 16:06:06 +02:00
|
|
|
void set_method(const HTTPServerEnums::HTTPMethod method);
|
|
|
|
|
2022-07-01 01:03:23 +02:00
|
|
|
//virtual String get_path_full() const;
|
2022-06-30 18:06:02 +02:00
|
|
|
|
2023-08-28 12:54:30 +02:00
|
|
|
bool sent();
|
|
|
|
|
2022-06-30 18:06:02 +02:00
|
|
|
SimpleWebServerRequest();
|
|
|
|
~SimpleWebServerRequest();
|
|
|
|
|
2022-07-01 17:40:47 +02:00
|
|
|
HTTPServerSimple *_server;
|
2022-07-24 02:40:39 +02:00
|
|
|
Ref<HTTPServerConnection> _connection;
|
2022-07-01 17:40:47 +02:00
|
|
|
|
2023-08-28 12:54:30 +02:00
|
|
|
FileAccess *_sending_file_fa;
|
|
|
|
|
2022-06-30 18:06:02 +02:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2022-07-01 17:40:47 +02:00
|
|
|
|
2022-12-21 14:52:11 +01:00
|
|
|
HashMap<String, String> _post_parameters;
|
|
|
|
HashMap<String, String> _get_parameters;
|
2023-12-22 13:02:17 +01:00
|
|
|
HashMap<String, String> _header_parameters;
|
2022-07-01 17:40:47 +02:00
|
|
|
String _parser_path;
|
|
|
|
String _host;
|
2022-07-20 21:29:59 +02:00
|
|
|
|
|
|
|
struct FileEntry {
|
2024-03-09 23:39:33 +01:00
|
|
|
enum FileEntryType {
|
|
|
|
FILE_ENTRY_TYPE_MEMORY = 0,
|
|
|
|
FILE_ENTRY_TYPE_TEMP_FILE = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
mutable bool moved;
|
|
|
|
|
|
|
|
FileEntryType type;
|
2022-07-20 21:29:59 +02:00
|
|
|
String file_name;
|
2022-07-20 22:53:55 +02:00
|
|
|
PoolByteArray data;
|
2022-07-20 21:29:59 +02:00
|
|
|
String key; //form name key
|
2024-03-09 23:39:33 +01:00
|
|
|
mutable String path;
|
|
|
|
|
|
|
|
FileEntry() {
|
|
|
|
moved = false;
|
|
|
|
}
|
2022-07-20 21:29:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Vector<FileEntry> _files;
|
2022-07-21 15:51:44 +02:00
|
|
|
|
|
|
|
struct CookieData {
|
|
|
|
String key;
|
|
|
|
String value;
|
|
|
|
};
|
|
|
|
|
|
|
|
Vector<CookieData> _cookies;
|
2022-07-21 16:06:06 +02:00
|
|
|
HTTPServerEnums::HTTPMethod _method;
|
2022-06-30 18:06:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|