| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "http_client.h" |
| 34 |
|
| 35 |
#include "core/crypto/crypto.h" |
| 36 |
|
| 37 |
class HTTPClientTCP : public HTTPClient { |
| 38 |
GDSOFTCLASS(HTTPClientTCP, HTTPClient); |
| 39 |
|
| 40 |
private: |
| 41 |
Status status = STATUS_DISCONNECTED; |
| 42 |
IP::ResolverID resolving = IP::RESOLVER_INVALID_ID; |
| 43 |
Array ip_candidates; |
| 44 |
int conn_port = -1; |
| 45 |
String conn_host; |
| 46 |
int server_port = -1; |
| 47 |
String server_host; |
| 48 |
int http_proxy_port = -1; |
| 49 |
String http_proxy_host; |
| 50 |
int https_proxy_port = -1; |
| 51 |
String https_proxy_host; |
| 52 |
bool blocking = false; |
| 53 |
bool handshaking = false; |
| 54 |
bool head_request = false; |
| 55 |
Ref<TLSOptions> tls_options; |
| 56 |
|
| 57 |
Vector<uint8_t> response_str; |
| 58 |
|
| 59 |
bool chunked = false; |
| 60 |
Vector<uint8_t> chunk; |
| 61 |
int chunk_left = 0; |
| 62 |
bool chunk_trailer_part = false; |
| 63 |
int64_t body_size = -1; |
| 64 |
int64_t body_left = 0; |
| 65 |
bool read_until_eof = false; |
| 66 |
|
| 67 |
Ref<StreamPeerBuffer> request_buffer; |
| 68 |
Ref<StreamPeerTCP> tcp_connection; |
| 69 |
Ref<StreamPeer> connection; |
| 70 |
Ref<HTTPClientTCP> proxy_client; |
| 71 |
|
| 72 |
int response_num = 0; |
| 73 |
Vector<String> response_headers; |
| 74 |
|
| 75 |
int read_chunk_size = 65536; |
| 76 |
|
| 77 |
Error _get_http_data(uint8_t *p_buffer, int p_bytes, int &r_received); |
| 78 |
|
| 79 |
public: |
| 80 |
static HTTPClient *_create_func(bool p_notify_postinitialize); |
| 81 |
|
| 82 |
Error request(Method p_method, const String &p_url, const Vector<String> &p_headers, const uint8_t *p_body, int p_body_size) override; |
| 83 |
|
| 84 |
Error connect_to_host(const String &p_host, int p_port = -1, Ref<TLSOptions> p_tls_options = Ref<TLSOptions>()) override; |
| 85 |
void set_connection(const Ref<StreamPeer> &p_connection) override; |
| 86 |
Ref<StreamPeer> get_connection() const override; |
| 87 |
void close() override; |
| 88 |
Status get_status() const override; |
| 89 |
bool has_response() const override; |
| 90 |
bool is_response_chunked() const override; |
| 91 |
int get_response_code() const override; |
| 92 |
Error get_response_headers(List<String> *r_response) override; |
| 93 |
int64_t get_response_body_length() const override; |
| 94 |
PackedByteArray read_response_body_chunk() override; |
| 95 |
void set_blocking_mode(bool p_enable) override; |
| 96 |
bool is_blocking_mode_enabled() const override; |
| 97 |
void set_read_chunk_size(int p_size) override; |
| 98 |
int get_read_chunk_size() const override; |
| 99 |
Error poll() override; |
| 100 |
void set_http_proxy(const String &p_host, int p_port) override; |
| 101 |
void set_https_proxy(const String &p_host, int p_port) override; |
| 102 |
HTTPClientTCP(); |
| 103 |
}; |