2016-06-18 12:46:12 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* http_request.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* 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. */
|
|
|
|
/**************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2016-03-04 14:09:45 +00:00
|
|
|
#include "http_request.h"
|
2020-05-21 08:05:32 +00:00
|
|
|
#include "core/io/compression.h"
|
2021-08-12 23:05:59 +00:00
|
|
|
#include "scene/main/timer.h"
|
2016-03-04 14:09:45 +00:00
|
|
|
|
|
|
|
Error HTTPRequest::_request() {
|
2023-01-20 00:51:35 +00:00
|
|
|
return client->connect_to_host(url, port, use_tls ? tls_options : nullptr);
|
2016-03-04 14:09:45 +00:00
|
|
|
}
|
|
|
|
|
2016-03-12 13:44:12 +00:00
|
|
|
Error HTTPRequest::_parse_url(const String &p_url) {
|
2022-09-07 06:25:47 +00:00
|
|
|
use_tls = false;
|
2016-03-04 14:09:45 +00:00
|
|
|
request_string = "";
|
|
|
|
port = 80;
|
|
|
|
request_sent = false;
|
|
|
|
got_response = false;
|
|
|
|
body_len = -1;
|
2022-02-01 18:19:13 +00:00
|
|
|
body.clear();
|
2021-02-10 18:22:13 +00:00
|
|
|
downloaded.set(0);
|
2022-07-31 16:02:41 +00:00
|
|
|
final_body_size.set(0);
|
2016-03-04 14:09:45 +00:00
|
|
|
redirections = 0;
|
|
|
|
|
2021-04-26 07:33:28 +00:00
|
|
|
String scheme;
|
|
|
|
Error err = p_url.parse_url(scheme, url, port, request_string);
|
|
|
|
ERR_FAIL_COND_V_MSG(err != OK, err, "Error parsing URL: " + p_url + ".");
|
|
|
|
if (scheme == "https://") {
|
2022-09-07 06:25:47 +00:00
|
|
|
use_tls = true;
|
2021-04-26 07:33:28 +00:00
|
|
|
} else if (scheme != "http://") {
|
|
|
|
ERR_FAIL_V_MSG(ERR_INVALID_PARAMETER, "Invalid URL scheme: " + scheme + ".");
|
2016-03-04 14:09:45 +00:00
|
|
|
}
|
2021-04-26 07:33:28 +00:00
|
|
|
if (port == 0) {
|
2022-09-07 06:25:47 +00:00
|
|
|
port = use_tls ? 443 : 80;
|
2016-03-04 14:09:45 +00:00
|
|
|
}
|
2021-04-26 07:33:28 +00:00
|
|
|
if (request_string.is_empty()) {
|
|
|
|
request_string = "/";
|
2016-03-04 14:09:45 +00:00
|
|
|
}
|
2016-03-12 13:44:12 +00:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2020-05-21 08:05:32 +00:00
|
|
|
bool HTTPRequest::has_header(const PackedStringArray &p_headers, const String &p_header_name) {
|
|
|
|
bool exists = false;
|
|
|
|
|
|
|
|
String lower_case_header_name = p_header_name.to_lower();
|
|
|
|
for (int i = 0; i < p_headers.size() && !exists; i++) {
|
|
|
|
String sanitized = p_headers[i].strip_edges().to_lower();
|
|
|
|
if (sanitized.begins_with(lower_case_header_name)) {
|
|
|
|
exists = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return exists;
|
|
|
|
}
|
|
|
|
|
|
|
|
String HTTPRequest::get_header_value(const PackedStringArray &p_headers, const String &p_header_name) {
|
|
|
|
String value = "";
|
|
|
|
|
|
|
|
String lowwer_case_header_name = p_header_name.to_lower();
|
|
|
|
for (int i = 0; i < p_headers.size(); i++) {
|
2022-01-14 02:22:23 +00:00
|
|
|
if (p_headers[i].find(":") > 0) {
|
2020-05-21 08:05:32 +00:00
|
|
|
Vector<String> parts = p_headers[i].split(":", false, 1);
|
2022-01-14 02:22:23 +00:00
|
|
|
if (parts.size() > 1 && parts[0].strip_edges().to_lower() == lowwer_case_header_name) {
|
2020-05-21 08:05:32 +00:00
|
|
|
value = parts[1].strip_edges();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2023-01-20 00:51:35 +00:00
|
|
|
Error HTTPRequest::request(const String &p_url, const Vector<String> &p_custom_headers, HTTPClient::Method p_method, const String &p_request_data) {
|
2022-01-13 23:20:58 +00:00
|
|
|
// Copy the string into a raw buffer.
|
2020-05-21 08:05:32 +00:00
|
|
|
Vector<uint8_t> raw_data;
|
|
|
|
|
|
|
|
CharString charstr = p_request_data.utf8();
|
|
|
|
size_t len = charstr.length();
|
2021-09-29 12:54:43 +00:00
|
|
|
if (len > 0) {
|
|
|
|
raw_data.resize(len);
|
|
|
|
uint8_t *w = raw_data.ptrw();
|
|
|
|
memcpy(w, charstr.ptr(), len);
|
|
|
|
}
|
2020-05-21 08:05:32 +00:00
|
|
|
|
2023-01-20 00:51:35 +00:00
|
|
|
return request_raw(p_url, p_custom_headers, p_method, raw_data);
|
2020-05-21 08:05:32 +00:00
|
|
|
}
|
|
|
|
|
2023-01-20 00:51:35 +00:00
|
|
|
Error HTTPRequest::request_raw(const String &p_url, const Vector<String> &p_custom_headers, HTTPClient::Method p_method, const Vector<uint8_t> &p_request_data_raw) {
|
2016-03-12 13:44:12 +00:00
|
|
|
ERR_FAIL_COND_V(!is_inside_tree(), ERR_UNCONFIGURED);
|
2019-08-08 20:11:48 +00:00
|
|
|
ERR_FAIL_COND_V_MSG(requesting, ERR_BUSY, "HTTPRequest is processing a request. Wait for completion or cancel it before attempting a new one.");
|
2016-03-12 13:44:12 +00:00
|
|
|
|
2019-07-04 13:17:52 +00:00
|
|
|
if (timeout > 0) {
|
|
|
|
timer->stop();
|
|
|
|
timer->start(timeout);
|
|
|
|
}
|
|
|
|
|
2016-08-31 20:59:09 +00:00
|
|
|
method = p_method;
|
|
|
|
|
2016-03-12 13:44:12 +00:00
|
|
|
Error err = _parse_url(p_url);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (err) {
|
2016-07-24 19:09:43 +00:00
|
|
|
return err;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-07-24 19:09:43 +00:00
|
|
|
|
2016-03-12 13:44:12 +00:00
|
|
|
headers = p_custom_headers;
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2020-05-21 08:05:32 +00:00
|
|
|
if (accept_gzip) {
|
2022-01-14 02:22:23 +00:00
|
|
|
// If the user has specified an Accept-Encoding header, don't overwrite it.
|
2020-05-21 08:05:32 +00:00
|
|
|
if (!has_header(headers, "Accept-Encoding")) {
|
|
|
|
headers.push_back("Accept-Encoding: gzip, deflate");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
request_data = p_request_data_raw;
|
2016-08-31 20:59:09 +00:00
|
|
|
|
2016-07-24 19:09:43 +00:00
|
|
|
requesting = true;
|
|
|
|
|
2021-02-10 18:22:13 +00:00
|
|
|
if (use_threads.is_set()) {
|
|
|
|
thread_done.clear();
|
|
|
|
thread_request_quit.clear();
|
2016-07-24 19:09:43 +00:00
|
|
|
client->set_blocking_mode(true);
|
2021-01-19 12:29:41 +00:00
|
|
|
thread.start(_thread_func, this);
|
2016-07-24 19:09:43 +00:00
|
|
|
} else {
|
|
|
|
client->set_blocking_mode(false);
|
|
|
|
err = _request();
|
|
|
|
if (err != OK) {
|
2022-07-31 19:56:13 +00:00
|
|
|
_defer_done(RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray());
|
2016-07-24 19:09:43 +00:00
|
|
|
return ERR_CANT_CONNECT;
|
|
|
|
}
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2017-01-10 21:02:19 +00:00
|
|
|
set_process_internal(true);
|
2016-03-04 14:09:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-24 19:09:43 +00:00
|
|
|
return OK;
|
2016-03-04 14:09:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-24 19:09:43 +00:00
|
|
|
void HTTPRequest::_thread_func(void *p_userdata) {
|
2022-04-05 10:40:26 +00:00
|
|
|
HTTPRequest *hr = static_cast<HTTPRequest *>(p_userdata);
|
2016-07-24 19:09:43 +00:00
|
|
|
|
|
|
|
Error err = hr->_request();
|
|
|
|
|
|
|
|
if (err != OK) {
|
2022-07-31 19:56:13 +00:00
|
|
|
hr->_defer_done(RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray());
|
2016-07-24 19:09:43 +00:00
|
|
|
} else {
|
2021-02-10 18:22:13 +00:00
|
|
|
while (!hr->thread_request_quit.is_set()) {
|
2016-07-24 19:09:43 +00:00
|
|
|
bool exit = hr->_update_connection();
|
2020-05-14 14:41:43 +00:00
|
|
|
if (exit) {
|
2016-07-24 19:09:43 +00:00
|
|
|
break;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-07-24 19:09:43 +00:00
|
|
|
OS::get_singleton()->delay_usec(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-10 18:22:13 +00:00
|
|
|
hr->thread_done.set();
|
2016-07-24 19:09:43 +00:00
|
|
|
}
|
|
|
|
|
2016-03-04 14:09:45 +00:00
|
|
|
void HTTPRequest::cancel_request() {
|
2019-07-04 13:17:52 +00:00
|
|
|
timer->stop();
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!requesting) {
|
2016-03-04 14:09:45 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2021-02-10 18:22:13 +00:00
|
|
|
if (!use_threads.is_set()) {
|
2017-01-10 21:02:19 +00:00
|
|
|
set_process_internal(false);
|
2016-07-24 19:09:43 +00:00
|
|
|
} else {
|
2021-02-10 18:22:13 +00:00
|
|
|
thread_request_quit.set();
|
2023-04-27 16:34:30 +00:00
|
|
|
if (thread.is_started()) {
|
|
|
|
thread.wait_to_finish();
|
|
|
|
}
|
2016-03-04 14:09:45 +00:00
|
|
|
}
|
|
|
|
|
2022-04-12 07:12:40 +00:00
|
|
|
file.unref();
|
2022-07-31 16:02:41 +00:00
|
|
|
decompressor.unref();
|
2016-03-04 14:09:45 +00:00
|
|
|
client->close();
|
2022-02-01 18:19:13 +00:00
|
|
|
body.clear();
|
2016-03-04 14:09:45 +00:00
|
|
|
got_response = false;
|
|
|
|
response_code = -1;
|
|
|
|
request_sent = false;
|
|
|
|
requesting = false;
|
|
|
|
}
|
|
|
|
|
2016-03-12 13:44:12 +00:00
|
|
|
bool HTTPRequest::_handle_response(bool *ret_value) {
|
|
|
|
if (!client->has_response()) {
|
2022-07-31 19:56:13 +00:00
|
|
|
_defer_done(RESULT_NO_RESPONSE, 0, PackedStringArray(), PackedByteArray());
|
2016-03-12 13:44:12 +00:00
|
|
|
*ret_value = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
got_response = true;
|
|
|
|
response_code = client->get_response_code();
|
|
|
|
List<String> rheaders;
|
|
|
|
client->get_response_headers(&rheaders);
|
2022-02-01 18:19:13 +00:00
|
|
|
response_headers.clear();
|
2021-02-10 18:22:13 +00:00
|
|
|
downloaded.set(0);
|
2022-07-31 16:02:41 +00:00
|
|
|
final_body_size.set(0);
|
|
|
|
decompressor.unref();
|
|
|
|
|
2021-07-24 13:46:25 +00:00
|
|
|
for (const String &E : rheaders) {
|
2021-07-16 03:45:57 +00:00
|
|
|
response_headers.push_back(E);
|
2016-03-12 13:44:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (response_code == 301 || response_code == 302) {
|
2022-01-13 23:20:58 +00:00
|
|
|
// Handle redirect.
|
2017-12-12 19:02:25 +00:00
|
|
|
|
2016-03-12 13:44:12 +00:00
|
|
|
if (max_redirects >= 0 && redirections >= max_redirects) {
|
2022-07-31 19:56:13 +00:00
|
|
|
_defer_done(RESULT_REDIRECT_LIMIT_REACHED, response_code, response_headers, PackedByteArray());
|
2016-03-12 13:44:12 +00:00
|
|
|
*ret_value = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
String new_request;
|
|
|
|
|
2021-07-24 13:46:25 +00:00
|
|
|
for (const String &E : rheaders) {
|
2021-07-16 03:45:57 +00:00
|
|
|
if (E.findn("Location: ") != -1) {
|
|
|
|
new_request = E.substr(9, E.length()).strip_edges();
|
2016-03-12 13:44:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-09 09:42:46 +00:00
|
|
|
if (!new_request.is_empty()) {
|
2022-01-13 23:20:58 +00:00
|
|
|
// Process redirect.
|
2016-03-12 13:44:12 +00:00
|
|
|
client->close();
|
2022-01-13 23:20:58 +00:00
|
|
|
int new_redirs = redirections + 1; // Because _request() will clear it.
|
2016-03-12 13:44:12 +00:00
|
|
|
Error err;
|
|
|
|
if (new_request.begins_with("http")) {
|
2022-01-13 23:20:58 +00:00
|
|
|
// New url, new request.
|
2019-01-14 22:04:47 +00:00
|
|
|
_parse_url(new_request);
|
2016-03-12 13:44:12 +00:00
|
|
|
} else {
|
|
|
|
request_string = new_request;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = _request();
|
|
|
|
if (err == OK) {
|
|
|
|
request_sent = false;
|
|
|
|
got_response = false;
|
|
|
|
body_len = -1;
|
2022-02-01 18:19:13 +00:00
|
|
|
body.clear();
|
2021-02-10 18:22:13 +00:00
|
|
|
downloaded.set(0);
|
2022-07-31 16:02:41 +00:00
|
|
|
final_body_size.set(0);
|
2016-03-12 13:44:12 +00:00
|
|
|
redirections = new_redirs;
|
|
|
|
*ret_value = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-31 16:02:41 +00:00
|
|
|
// Check if we need to start streaming decompression.
|
|
|
|
String content_encoding;
|
|
|
|
if (accept_gzip) {
|
|
|
|
content_encoding = get_header_value(response_headers, "Content-Encoding").to_lower();
|
|
|
|
}
|
|
|
|
if (content_encoding == "gzip") {
|
|
|
|
decompressor.instantiate();
|
2022-11-20 21:17:40 +00:00
|
|
|
decompressor->start_decompression(false, get_download_chunk_size());
|
2022-07-31 16:02:41 +00:00
|
|
|
} else if (content_encoding == "deflate") {
|
|
|
|
decompressor.instantiate();
|
2022-11-20 21:17:40 +00:00
|
|
|
decompressor->start_decompression(true, get_download_chunk_size());
|
2022-07-31 16:02:41 +00:00
|
|
|
}
|
|
|
|
|
2016-03-12 13:44:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-04 14:09:45 +00:00
|
|
|
bool HTTPRequest::_update_connection() {
|
|
|
|
switch (client->get_status()) {
|
|
|
|
case HTTPClient::STATUS_DISCONNECTED: {
|
2022-07-31 19:56:13 +00:00
|
|
|
_defer_done(RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray());
|
2022-01-13 23:20:58 +00:00
|
|
|
return true; // End it, since it's disconnected.
|
2016-03-04 14:09:45 +00:00
|
|
|
} break;
|
|
|
|
case HTTPClient::STATUS_RESOLVING: {
|
|
|
|
client->poll();
|
2022-01-13 23:20:58 +00:00
|
|
|
// Must wait.
|
2016-03-04 14:09:45 +00:00
|
|
|
return false;
|
|
|
|
} break;
|
|
|
|
case HTTPClient::STATUS_CANT_RESOLVE: {
|
2022-07-31 19:56:13 +00:00
|
|
|
_defer_done(RESULT_CANT_RESOLVE, 0, PackedStringArray(), PackedByteArray());
|
2016-03-04 14:09:45 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case HTTPClient::STATUS_CONNECTING: {
|
|
|
|
client->poll();
|
2022-01-13 23:20:58 +00:00
|
|
|
// Must wait.
|
2016-03-04 14:09:45 +00:00
|
|
|
return false;
|
2022-01-13 23:20:58 +00:00
|
|
|
} break; // Connecting to IP.
|
2016-03-04 14:09:45 +00:00
|
|
|
case HTTPClient::STATUS_CANT_CONNECT: {
|
2022-07-31 19:56:13 +00:00
|
|
|
_defer_done(RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray());
|
2016-03-04 14:09:45 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case HTTPClient::STATUS_CONNECTED: {
|
|
|
|
if (request_sent) {
|
|
|
|
if (!got_response) {
|
2022-01-13 23:20:58 +00:00
|
|
|
// No body.
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2016-03-12 13:44:12 +00:00
|
|
|
bool ret_value;
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (_handle_response(&ret_value)) {
|
2016-03-12 13:44:12 +00:00
|
|
|
return ret_value;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2022-07-31 19:56:13 +00:00
|
|
|
_defer_done(RESULT_SUCCESS, response_code, response_headers, PackedByteArray());
|
2016-03-04 14:09:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-04-08 09:03:37 +00:00
|
|
|
if (body_len < 0) {
|
2022-01-13 23:20:58 +00:00
|
|
|
// Chunked transfer is done.
|
2022-07-31 19:56:13 +00:00
|
|
|
_defer_done(RESULT_SUCCESS, response_code, response_headers, body);
|
2016-03-04 14:09:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-07-31 19:56:13 +00:00
|
|
|
_defer_done(RESULT_CHUNKED_BODY_SIZE_MISMATCH, response_code, response_headers, PackedByteArray());
|
2016-03-04 14:09:45 +00:00
|
|
|
return true;
|
2022-01-13 23:20:58 +00:00
|
|
|
// Request might have been done.
|
2016-03-04 14:09:45 +00:00
|
|
|
} else {
|
2022-01-13 23:20:58 +00:00
|
|
|
// Did not request yet, do request.
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2021-03-23 14:17:32 +00:00
|
|
|
int size = request_data.size();
|
|
|
|
Error err = client->request(method, request_string, headers, size > 0 ? request_data.ptr() : nullptr, size);
|
2016-03-04 14:09:45 +00:00
|
|
|
if (err != OK) {
|
2022-07-31 19:56:13 +00:00
|
|
|
_defer_done(RESULT_CONNECTION_ERROR, 0, PackedStringArray(), PackedByteArray());
|
2016-03-04 14:09:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
request_sent = true;
|
|
|
|
return false;
|
|
|
|
}
|
2022-01-13 23:20:58 +00:00
|
|
|
} break; // Connected: break requests only accepted here.
|
2016-03-04 14:09:45 +00:00
|
|
|
case HTTPClient::STATUS_REQUESTING: {
|
2022-01-13 23:20:58 +00:00
|
|
|
// Must wait, still requesting.
|
2016-03-04 14:09:45 +00:00
|
|
|
client->poll();
|
|
|
|
return false;
|
|
|
|
|
2022-01-13 23:20:58 +00:00
|
|
|
} break; // Request in progress.
|
2016-03-04 14:09:45 +00:00
|
|
|
case HTTPClient::STATUS_BODY: {
|
|
|
|
if (!got_response) {
|
2016-03-12 13:44:12 +00:00
|
|
|
bool ret_value;
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (_handle_response(&ret_value)) {
|
2016-03-12 13:44:12 +00:00
|
|
|
return ret_value;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-03-04 14:09:45 +00:00
|
|
|
|
|
|
|
if (!client->is_response_chunked() && client->get_response_body_length() == 0) {
|
2022-07-31 19:56:13 +00:00
|
|
|
_defer_done(RESULT_SUCCESS, response_code, response_headers, PackedByteArray());
|
2016-03-04 14:09:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:46:14 +00:00
|
|
|
// No body len (-1) if chunked or no content-length header was provided.
|
|
|
|
// Change your webserver configuration if you want body len.
|
|
|
|
body_len = client->get_response_body_length();
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2018-09-11 15:46:14 +00:00
|
|
|
if (body_size_limit >= 0 && body_len > body_size_limit) {
|
2022-07-31 19:56:13 +00:00
|
|
|
_defer_done(RESULT_BODY_SIZE_LIMIT_EXCEEDED, response_code, response_headers, PackedByteArray());
|
2018-09-11 15:46:14 +00:00
|
|
|
return true;
|
2016-03-04 14:09:45 +00:00
|
|
|
}
|
|
|
|
|
2021-12-09 09:42:46 +00:00
|
|
|
if (!download_to_file.is_empty()) {
|
2016-03-12 13:44:12 +00:00
|
|
|
file = FileAccess::open(download_to_file, FileAccess::WRITE);
|
2022-03-23 09:08:58 +00:00
|
|
|
if (file.is_null()) {
|
2022-07-31 19:56:13 +00:00
|
|
|
_defer_done(RESULT_DOWNLOAD_FILE_CANT_OPEN, response_code, response_headers, PackedByteArray());
|
2016-07-24 19:09:43 +00:00
|
|
|
return true;
|
2016-03-12 13:44:12 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-04 14:09:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
client->poll();
|
2021-02-27 17:01:40 +00:00
|
|
|
if (client->get_status() != HTTPClient::STATUS_BODY) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2022-11-20 21:17:40 +00:00
|
|
|
PackedByteArray chunk;
|
|
|
|
if (decompressor.is_null()) {
|
|
|
|
// Chunk can be read directly.
|
|
|
|
chunk = client->read_response_body_chunk();
|
|
|
|
downloaded.add(chunk.size());
|
|
|
|
} else {
|
|
|
|
// Chunk is the result of decompression.
|
|
|
|
PackedByteArray compressed = client->read_response_body_chunk();
|
|
|
|
downloaded.add(compressed.size());
|
|
|
|
|
|
|
|
int pos = 0;
|
|
|
|
int left = compressed.size();
|
|
|
|
while (left) {
|
|
|
|
int w = 0;
|
|
|
|
Error err = decompressor->put_partial_data(compressed.ptr() + pos, left, w);
|
|
|
|
if (err == OK) {
|
|
|
|
PackedByteArray dc;
|
|
|
|
dc.resize(decompressor->get_available_bytes());
|
|
|
|
err = decompressor->get_data(dc.ptrw(), dc.size());
|
|
|
|
chunk.append_array(dc);
|
|
|
|
}
|
|
|
|
if (err != OK) {
|
|
|
|
_defer_done(RESULT_BODY_DECOMPRESS_FAILED, response_code, response_headers, PackedByteArray());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// We need this check here because a "zip bomb" could result in a chunk of few kilos decompressing into gigabytes of data.
|
|
|
|
if (body_size_limit >= 0 && final_body_size.get() + chunk.size() > body_size_limit) {
|
|
|
|
_defer_done(RESULT_BODY_SIZE_LIMIT_EXCEEDED, response_code, response_headers, PackedByteArray());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
pos += w;
|
|
|
|
left -= w;
|
2022-07-31 16:02:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
final_body_size.add(chunk.size());
|
|
|
|
|
|
|
|
if (body_size_limit >= 0 && final_body_size.get() > body_size_limit) {
|
2022-07-31 19:56:13 +00:00
|
|
|
_defer_done(RESULT_BODY_SIZE_LIMIT_EXCEEDED, response_code, response_headers, PackedByteArray());
|
2022-07-31 16:02:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2021-05-31 13:42:31 +00:00
|
|
|
if (chunk.size()) {
|
2022-03-23 09:08:58 +00:00
|
|
|
if (file.is_valid()) {
|
2021-05-31 13:42:31 +00:00
|
|
|
const uint8_t *r = chunk.ptr();
|
|
|
|
file->store_buffer(r, chunk.size());
|
|
|
|
if (file->get_error() != OK) {
|
2022-07-31 19:56:13 +00:00
|
|
|
_defer_done(RESULT_DOWNLOAD_FILE_WRITE_ERROR, response_code, response_headers, PackedByteArray());
|
2021-05-31 13:42:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
body.append_array(chunk);
|
2016-03-12 13:44:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-04 14:09:45 +00:00
|
|
|
if (body_len >= 0) {
|
2021-02-10 18:22:13 +00:00
|
|
|
if (downloaded.get() == body_len) {
|
2022-07-31 19:56:13 +00:00
|
|
|
_defer_done(RESULT_SUCCESS, response_code, response_headers, body);
|
2016-03-04 14:09:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-09-11 15:46:14 +00:00
|
|
|
} else if (client->get_status() == HTTPClient::STATUS_DISCONNECTED) {
|
|
|
|
// We read till EOF, with no errors. Request is done.
|
2022-07-31 19:56:13 +00:00
|
|
|
_defer_done(RESULT_SUCCESS, response_code, response_headers, body);
|
2021-02-27 20:46:27 +00:00
|
|
|
return true;
|
2016-03-04 14:09:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
2022-01-13 23:20:58 +00:00
|
|
|
} break; // Request resulted in body: break which must be read.
|
2016-03-04 14:09:45 +00:00
|
|
|
case HTTPClient::STATUS_CONNECTION_ERROR: {
|
2022-07-31 19:56:13 +00:00
|
|
|
_defer_done(RESULT_CONNECTION_ERROR, 0, PackedStringArray(), PackedByteArray());
|
2016-03-04 14:09:45 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
2022-09-07 06:25:47 +00:00
|
|
|
case HTTPClient::STATUS_TLS_HANDSHAKE_ERROR: {
|
2022-07-31 19:56:13 +00:00
|
|
|
_defer_done(RESULT_TLS_HANDSHAKE_ERROR, 0, PackedStringArray(), PackedByteArray());
|
2016-03-04 14:09:45 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR_FAIL_V(false);
|
|
|
|
}
|
|
|
|
|
2022-07-31 19:56:13 +00:00
|
|
|
void HTTPRequest::_defer_done(int p_status, int p_code, const PackedStringArray &p_headers, const PackedByteArray &p_data) {
|
2023-12-18 14:46:56 +00:00
|
|
|
callable_mp(this, &HTTPRequest::_request_done).call_deferred(p_status, p_code, p_headers, p_data);
|
2022-07-31 19:56:13 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 08:05:32 +00:00
|
|
|
void HTTPRequest::_request_done(int p_status, int p_code, const PackedStringArray &p_headers, const PackedByteArray &p_data) {
|
2016-07-24 19:09:43 +00:00
|
|
|
cancel_request();
|
2020-05-21 08:05:32 +00:00
|
|
|
|
2022-01-24 13:24:45 +00:00
|
|
|
emit_signal(SNAME("request_completed"), p_status, p_code, p_headers, p_data);
|
2016-07-24 19:09:43 +00:00
|
|
|
}
|
|
|
|
|
2016-03-04 14:09:45 +00:00
|
|
|
void HTTPRequest::_notification(int p_what) {
|
2022-02-15 17:06:48 +00:00
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_INTERNAL_PROCESS: {
|
|
|
|
if (use_threads.is_set()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool done = _update_connection();
|
|
|
|
if (done) {
|
|
|
|
set_process_internal(false);
|
|
|
|
}
|
|
|
|
} break;
|
2016-07-24 19:09:43 +00:00
|
|
|
|
2022-02-15 17:06:48 +00:00
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
|
|
|
if (requesting) {
|
|
|
|
cancel_request();
|
|
|
|
}
|
|
|
|
} break;
|
2016-03-04 14:09:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTTPRequest::set_use_threads(bool p_use) {
|
2019-07-01 07:15:35 +00:00
|
|
|
ERR_FAIL_COND(get_http_client_status() != HTTPClient::STATUS_DISCONNECTED);
|
2023-12-01 18:39:09 +00:00
|
|
|
#ifdef THREADS_ENABLED
|
2021-02-10 18:22:13 +00:00
|
|
|
use_threads.set_to(p_use);
|
2023-12-01 18:39:09 +00:00
|
|
|
#endif
|
2016-03-04 14:09:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HTTPRequest::is_using_threads() const {
|
2021-02-10 18:22:13 +00:00
|
|
|
return use_threads.is_set();
|
2016-03-04 14:09:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 08:05:32 +00:00
|
|
|
void HTTPRequest::set_accept_gzip(bool p_gzip) {
|
|
|
|
accept_gzip = p_gzip;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HTTPRequest::is_accepting_gzip() const {
|
|
|
|
return accept_gzip;
|
|
|
|
}
|
|
|
|
|
2016-03-04 14:09:45 +00:00
|
|
|
void HTTPRequest::set_body_size_limit(int p_bytes) {
|
2019-07-01 07:15:35 +00:00
|
|
|
ERR_FAIL_COND(get_http_client_status() != HTTPClient::STATUS_DISCONNECTED);
|
2016-03-04 14:09:45 +00:00
|
|
|
|
|
|
|
body_size_limit = p_bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
int HTTPRequest::get_body_size_limit() const {
|
|
|
|
return body_size_limit;
|
|
|
|
}
|
|
|
|
|
2016-03-12 13:44:12 +00:00
|
|
|
void HTTPRequest::set_download_file(const String &p_file) {
|
2019-07-01 07:15:35 +00:00
|
|
|
ERR_FAIL_COND(get_http_client_status() != HTTPClient::STATUS_DISCONNECTED);
|
2016-03-12 13:44:12 +00:00
|
|
|
|
|
|
|
download_to_file = p_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
String HTTPRequest::get_download_file() const {
|
|
|
|
return download_to_file;
|
|
|
|
}
|
2019-11-24 12:20:24 +00:00
|
|
|
|
|
|
|
void HTTPRequest::set_download_chunk_size(int p_chunk_size) {
|
|
|
|
ERR_FAIL_COND(get_http_client_status() != HTTPClient::STATUS_DISCONNECTED);
|
|
|
|
|
|
|
|
client->set_read_chunk_size(p_chunk_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
int HTTPRequest::get_download_chunk_size() const {
|
|
|
|
return client->get_read_chunk_size();
|
|
|
|
}
|
|
|
|
|
2016-03-04 14:09:45 +00:00
|
|
|
HTTPClient::Status HTTPRequest::get_http_client_status() const {
|
|
|
|
return client->get_status();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTTPRequest::set_max_redirects(int p_max) {
|
|
|
|
max_redirects = p_max;
|
|
|
|
}
|
|
|
|
|
|
|
|
int HTTPRequest::get_max_redirects() const {
|
|
|
|
return max_redirects;
|
|
|
|
}
|
|
|
|
|
2016-03-12 13:44:12 +00:00
|
|
|
int HTTPRequest::get_downloaded_bytes() const {
|
2021-02-10 18:22:13 +00:00
|
|
|
return downloaded.get();
|
2016-03-12 13:44:12 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2016-03-12 13:44:12 +00:00
|
|
|
int HTTPRequest::get_body_size() const {
|
|
|
|
return body_len;
|
|
|
|
}
|
|
|
|
|
2021-12-09 03:34:32 +00:00
|
|
|
void HTTPRequest::set_http_proxy(const String &p_host, int p_port) {
|
|
|
|
client->set_http_proxy(p_host, p_port);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTTPRequest::set_https_proxy(const String &p_host, int p_port) {
|
|
|
|
client->set_https_proxy(p_host, p_port);
|
|
|
|
}
|
|
|
|
|
2022-03-27 15:49:39 +00:00
|
|
|
void HTTPRequest::set_timeout(double p_timeout) {
|
2019-07-04 13:17:52 +00:00
|
|
|
ERR_FAIL_COND(p_timeout < 0);
|
|
|
|
timeout = p_timeout;
|
|
|
|
}
|
|
|
|
|
2022-03-27 15:49:39 +00:00
|
|
|
double HTTPRequest::get_timeout() {
|
2019-07-04 13:17:52 +00:00
|
|
|
return timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTTPRequest::_timeout() {
|
|
|
|
cancel_request();
|
2022-07-31 19:56:13 +00:00
|
|
|
_defer_done(RESULT_TIMEOUT, 0, PackedStringArray(), PackedByteArray());
|
2019-07-04 13:17:52 +00:00
|
|
|
}
|
|
|
|
|
2023-01-20 00:51:35 +00:00
|
|
|
void HTTPRequest::set_tls_options(const Ref<TLSOptions> &p_options) {
|
|
|
|
ERR_FAIL_COND(p_options.is_null() || p_options->is_server());
|
|
|
|
tls_options = p_options;
|
|
|
|
}
|
|
|
|
|
2016-03-04 14:09:45 +00:00
|
|
|
void HTTPRequest::_bind_methods() {
|
2023-01-20 00:51:35 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("request", "url", "custom_headers", "method", "request_data"), &HTTPRequest::request, DEFVAL(PackedStringArray()), DEFVAL(HTTPClient::METHOD_GET), DEFVAL(String()));
|
|
|
|
ClassDB::bind_method(D_METHOD("request_raw", "url", "custom_headers", "method", "request_data_raw"), &HTTPRequest::request_raw, DEFVAL(PackedStringArray()), DEFVAL(HTTPClient::METHOD_GET), DEFVAL(PackedByteArray()));
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("cancel_request"), &HTTPRequest::cancel_request);
|
2023-01-20 00:51:35 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_tls_options", "client_options"), &HTTPRequest::set_tls_options);
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_http_client_status"), &HTTPRequest::get_http_client_status);
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_use_threads", "enable"), &HTTPRequest::set_use_threads);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_using_threads"), &HTTPRequest::is_using_threads);
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2020-05-21 08:05:32 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_accept_gzip", "enable"), &HTTPRequest::set_accept_gzip);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_accepting_gzip"), &HTTPRequest::is_accepting_gzip);
|
|
|
|
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_body_size_limit", "bytes"), &HTTPRequest::set_body_size_limit);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_body_size_limit"), &HTTPRequest::get_body_size_limit);
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_max_redirects", "amount"), &HTTPRequest::set_max_redirects);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_max_redirects"), &HTTPRequest::get_max_redirects);
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_download_file", "path"), &HTTPRequest::set_download_file);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_download_file"), &HTTPRequest::get_download_file);
|
2016-03-12 13:44:12 +00:00
|
|
|
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_downloaded_bytes"), &HTTPRequest::get_downloaded_bytes);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_body_size"), &HTTPRequest::get_body_size);
|
2016-03-12 13:44:12 +00:00
|
|
|
|
2019-07-04 13:17:52 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_timeout", "timeout"), &HTTPRequest::set_timeout);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_timeout"), &HTTPRequest::get_timeout);
|
|
|
|
|
2021-10-08 21:26:13 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_download_chunk_size", "chunk_size"), &HTTPRequest::set_download_chunk_size);
|
2019-11-24 12:20:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_download_chunk_size"), &HTTPRequest::get_download_chunk_size);
|
|
|
|
|
2021-12-09 03:34:32 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_http_proxy", "host", "port"), &HTTPRequest::set_http_proxy);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_https_proxy", "host", "port"), &HTTPRequest::set_https_proxy);
|
|
|
|
|
2018-01-11 22:35:12 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "download_file", PROPERTY_HINT_FILE), "set_download_file", "get_download_file");
|
2022-05-20 05:24:41 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "download_chunk_size", PROPERTY_HINT_RANGE, "256,16777216,suffix:B"), "set_download_chunk_size", "get_download_chunk_size");
|
2017-02-12 00:11:37 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_threads"), "set_use_threads", "is_using_threads");
|
2020-05-21 08:05:32 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "accept_gzip"), "set_accept_gzip", "is_accepting_gzip");
|
2022-05-20 05:24:41 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "body_size_limit", PROPERTY_HINT_RANGE, "-1,2000000000,suffix:B"), "set_body_size_limit", "get_body_size_limit");
|
2017-12-12 19:02:25 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_redirects", PROPERTY_HINT_RANGE, "-1,64"), "set_max_redirects", "get_max_redirects");
|
2022-05-20 05:24:41 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "timeout", PROPERTY_HINT_RANGE, "0,3600,0.1,or_greater,suffix:s"), "set_timeout", "get_timeout");
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2020-02-17 21:06:54 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("request_completed", PropertyInfo(Variant::INT, "result"), PropertyInfo(Variant::INT, "response_code"), PropertyInfo(Variant::PACKED_STRING_ARRAY, "headers"), PropertyInfo(Variant::PACKED_BYTE_ARRAY, "body")));
|
2016-03-04 14:09:45 +00:00
|
|
|
|
2017-08-20 15:45:01 +00:00
|
|
|
BIND_ENUM_CONSTANT(RESULT_SUCCESS);
|
|
|
|
BIND_ENUM_CONSTANT(RESULT_CHUNKED_BODY_SIZE_MISMATCH);
|
|
|
|
BIND_ENUM_CONSTANT(RESULT_CANT_CONNECT);
|
|
|
|
BIND_ENUM_CONSTANT(RESULT_CANT_RESOLVE);
|
|
|
|
BIND_ENUM_CONSTANT(RESULT_CONNECTION_ERROR);
|
2022-09-07 06:25:47 +00:00
|
|
|
BIND_ENUM_CONSTANT(RESULT_TLS_HANDSHAKE_ERROR);
|
2017-08-20 15:45:01 +00:00
|
|
|
BIND_ENUM_CONSTANT(RESULT_NO_RESPONSE);
|
|
|
|
BIND_ENUM_CONSTANT(RESULT_BODY_SIZE_LIMIT_EXCEEDED);
|
2020-09-11 10:22:10 +00:00
|
|
|
BIND_ENUM_CONSTANT(RESULT_BODY_DECOMPRESS_FAILED);
|
2017-08-20 15:45:01 +00:00
|
|
|
BIND_ENUM_CONSTANT(RESULT_REQUEST_FAILED);
|
|
|
|
BIND_ENUM_CONSTANT(RESULT_DOWNLOAD_FILE_CANT_OPEN);
|
|
|
|
BIND_ENUM_CONSTANT(RESULT_DOWNLOAD_FILE_WRITE_ERROR);
|
|
|
|
BIND_ENUM_CONSTANT(RESULT_REDIRECT_LIMIT_REACHED);
|
2019-07-04 13:17:52 +00:00
|
|
|
BIND_ENUM_CONSTANT(RESULT_TIMEOUT);
|
2016-03-04 14:09:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HTTPRequest::HTTPRequest() {
|
2021-03-23 16:03:29 +00:00
|
|
|
client = Ref<HTTPClient>(HTTPClient::create());
|
2023-01-20 00:51:35 +00:00
|
|
|
tls_options = TLSOptions::client();
|
2019-07-04 13:17:52 +00:00
|
|
|
timer = memnew(Timer);
|
|
|
|
timer->set_one_shot(true);
|
2020-02-21 17:28:45 +00:00
|
|
|
timer->connect("timeout", callable_mp(this, &HTTPRequest::_timeout));
|
2019-07-04 13:17:52 +00:00
|
|
|
add_child(timer);
|
2016-03-04 14:09:45 +00:00
|
|
|
}
|