/**************************************************************************/1/* http_client_tcp.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "http_client.h"3334#include "core/crypto/crypto.h"3536class HTTPClientTCP : public HTTPClient {37private:38Status status = STATUS_DISCONNECTED;39IP::ResolverID resolving = IP::RESOLVER_INVALID_ID;40Array ip_candidates;41int conn_port = -1; // Server to make requests to.42String conn_host;43int server_port = -1; // Server to connect to (might be a proxy server).44String server_host;45int http_proxy_port = -1; // Proxy server for http requests.46String http_proxy_host;47int https_proxy_port = -1; // Proxy server for https requests.48String https_proxy_host;49bool blocking = false;50bool handshaking = false;51bool head_request = false;52Ref<TLSOptions> tls_options;5354Vector<uint8_t> response_str;5556bool chunked = false;57Vector<uint8_t> chunk;58int chunk_left = 0;59bool chunk_trailer_part = false;60int64_t body_size = -1;61int64_t body_left = 0;62bool read_until_eof = false;6364Ref<StreamPeerBuffer> request_buffer;65Ref<StreamPeerTCP> tcp_connection;66Ref<StreamPeer> connection;67Ref<HTTPClientTCP> proxy_client; // Negotiate with proxy server.6869int response_num = 0;70Vector<String> response_headers;71// 64 KiB by default (favors fast download speeds at the cost of memory usage).72int read_chunk_size = 65536;7374Error _get_http_data(uint8_t *p_buffer, int p_bytes, int &r_received);7576public:77static HTTPClient *_create_func(bool p_notify_postinitialize);7879Error request(Method p_method, const String &p_url, const Vector<String> &p_headers, const uint8_t *p_body, int p_body_size) override;8081Error connect_to_host(const String &p_host, int p_port = -1, Ref<TLSOptions> p_tls_options = Ref<TLSOptions>()) override;82void set_connection(const Ref<StreamPeer> &p_connection) override;83Ref<StreamPeer> get_connection() const override;84void close() override;85Status get_status() const override;86bool has_response() const override;87bool is_response_chunked() const override;88int get_response_code() const override;89Error get_response_headers(List<String> *r_response) override;90int64_t get_response_body_length() const override;91PackedByteArray read_response_body_chunk() override;92void set_blocking_mode(bool p_enable) override;93bool is_blocking_mode_enabled() const override;94void set_read_chunk_size(int p_size) override;95int get_read_chunk_size() const override;96Error poll() override;97void set_http_proxy(const String &p_host, int p_port) override;98void set_https_proxy(const String &p_host, int p_port) override;99HTTPClientTCP();100};101102103