2017-10-26 03:39:41 +02:00
|
|
|
/**************************************************************************/
|
2021-03-23 17:03:29 +01:00
|
|
|
/* http_client_tcp.h */
|
2017-10-26 03:39:41 +02:00
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2019-06-17 12:42:05 +02:00
|
|
|
/* https://godotengine.org */
|
2017-10-26 03:39:41 +02:00
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 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. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2021-03-23 17:03:29 +01:00
|
|
|
#ifndef HTTP_CLIENT_TCP_H
|
|
|
|
#define HTTP_CLIENT_TCP_H
|
2017-10-26 03:39:41 +02:00
|
|
|
|
2021-03-23 17:03:29 +01:00
|
|
|
#include "http_client.h"
|
2017-10-26 03:39:41 +02:00
|
|
|
|
2023-01-20 01:51:35 +01:00
|
|
|
#include "core/crypto/crypto.h"
|
|
|
|
|
2021-03-23 17:03:29 +01:00
|
|
|
class HTTPClientTCP : public HTTPClient {
|
|
|
|
private:
|
|
|
|
Status status = STATUS_DISCONNECTED;
|
|
|
|
IP::ResolverID resolving = IP::RESOLVER_INVALID_ID;
|
2021-07-11 11:43:52 +02:00
|
|
|
Array ip_candidates;
|
2022-01-14 00:20:58 +01:00
|
|
|
int conn_port = -1; // Server to make requests to.
|
2021-03-23 17:03:29 +01:00
|
|
|
String conn_host;
|
2022-01-14 00:20:58 +01:00
|
|
|
int server_port = -1; // Server to connect to (might be a proxy server).
|
2021-07-03 07:11:59 +02:00
|
|
|
String server_host;
|
2022-01-14 00:20:58 +01:00
|
|
|
int http_proxy_port = -1; // Proxy server for http requests.
|
2021-07-03 07:11:59 +02:00
|
|
|
String http_proxy_host;
|
2022-01-14 00:20:58 +01:00
|
|
|
int https_proxy_port = -1; // Proxy server for https requests.
|
2021-07-03 07:11:59 +02:00
|
|
|
String https_proxy_host;
|
2021-03-23 17:03:29 +01:00
|
|
|
bool blocking = false;
|
|
|
|
bool handshaking = false;
|
|
|
|
bool head_request = false;
|
2023-01-20 01:51:35 +01:00
|
|
|
Ref<TLSOptions> tls_options;
|
2017-10-26 03:39:41 +02:00
|
|
|
|
2021-03-23 17:03:29 +01:00
|
|
|
Vector<uint8_t> response_str;
|
2017-10-26 03:39:41 +02:00
|
|
|
|
2021-03-23 17:03:29 +01:00
|
|
|
bool chunked = false;
|
|
|
|
Vector<uint8_t> chunk;
|
|
|
|
int chunk_left = 0;
|
|
|
|
bool chunk_trailer_part = false;
|
2021-12-30 01:16:19 +01:00
|
|
|
int64_t body_size = -1;
|
|
|
|
int64_t body_left = 0;
|
2021-03-23 17:03:29 +01:00
|
|
|
bool read_until_eof = false;
|
2018-02-17 17:42:58 +01:00
|
|
|
|
2022-02-03 01:33:15 +01:00
|
|
|
Ref<StreamPeerBuffer> request_buffer;
|
2021-03-23 17:03:29 +01:00
|
|
|
Ref<StreamPeerTCP> tcp_connection;
|
|
|
|
Ref<StreamPeer> connection;
|
2022-01-14 00:20:58 +01:00
|
|
|
Ref<HTTPClientTCP> proxy_client; // Negotiate with proxy server.
|
2021-03-23 17:03:29 +01:00
|
|
|
|
|
|
|
int response_num = 0;
|
|
|
|
Vector<String> response_headers;
|
|
|
|
// 64 KiB by default (favors fast download speeds at the cost of memory usage).
|
|
|
|
int read_chunk_size = 65536;
|
|
|
|
|
|
|
|
Error _get_http_data(uint8_t *p_buffer, int p_bytes, int &r_received);
|
|
|
|
|
|
|
|
public:
|
2024-04-22 16:34:44 +02:00
|
|
|
static HTTPClient *_create_func(bool p_notify_postinitialize);
|
2021-03-23 17:03:29 +01:00
|
|
|
|
|
|
|
Error request(Method p_method, const String &p_url, const Vector<String> &p_headers, const uint8_t *p_body, int p_body_size) override;
|
|
|
|
|
2023-01-20 01:51:35 +01:00
|
|
|
Error connect_to_host(const String &p_host, int p_port = -1, Ref<TLSOptions> p_tls_options = Ref<TLSOptions>()) override;
|
2021-03-23 17:03:29 +01:00
|
|
|
void set_connection(const Ref<StreamPeer> &p_connection) override;
|
|
|
|
Ref<StreamPeer> get_connection() const override;
|
|
|
|
void close() override;
|
|
|
|
Status get_status() const override;
|
|
|
|
bool has_response() const override;
|
|
|
|
bool is_response_chunked() const override;
|
|
|
|
int get_response_code() const override;
|
|
|
|
Error get_response_headers(List<String> *r_response) override;
|
2022-01-23 01:28:35 +01:00
|
|
|
int64_t get_response_body_length() const override;
|
2021-03-23 17:03:29 +01:00
|
|
|
PackedByteArray read_response_body_chunk() override;
|
|
|
|
void set_blocking_mode(bool p_enable) override;
|
|
|
|
bool is_blocking_mode_enabled() const override;
|
|
|
|
void set_read_chunk_size(int p_size) override;
|
|
|
|
int get_read_chunk_size() const override;
|
|
|
|
Error poll() override;
|
2021-07-03 07:11:59 +02:00
|
|
|
void set_http_proxy(const String &p_host, int p_port) override;
|
|
|
|
void set_https_proxy(const String &p_host, int p_port) override;
|
2021-03-23 17:03:29 +01:00
|
|
|
HTTPClientTCP();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // HTTP_CLIENT_TCP_H
|