summaryrefslogtreecommitdiff
path: root/core/io
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2019-11-24 13:20:24 +0100
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2019-11-24 19:32:20 +0100
commited19b4076e0ec9252202086e65ffcc42510b6cdd (patch)
tree58d0a83b8aa20f96df854259c06743e6dd69ff47 /core/io
parent37b230fe3af3c7e20a6f938d03b61a79b117d354 (diff)
Add download_chunk_size property to HTTPRequest.
This allows setting the `read_chunk_size` of the internal HTTPClient. This is important to reduce the allocation overhead and number of file writes when downloading large files, allowing for better download speed.
Diffstat (limited to 'core/io')
-rw-r--r--core/io/http_client.cpp6
-rw-r--r--core/io/http_client.h1
2 files changed, 7 insertions, 0 deletions
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index 170bef4430..382f900d59 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -713,6 +713,10 @@ void HTTPClient::set_read_chunk_size(int p_size) {
read_chunk_size = p_size;
}
+int HTTPClient::get_read_chunk_size() const {
+ return read_chunk_size;
+}
+
HTTPClient::HTTPClient() {
tcp_connection.instance();
@@ -816,6 +820,7 @@ void HTTPClient::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_response_body_length"), &HTTPClient::get_response_body_length);
ClassDB::bind_method(D_METHOD("read_response_body_chunk"), &HTTPClient::read_response_body_chunk);
ClassDB::bind_method(D_METHOD("set_read_chunk_size", "bytes"), &HTTPClient::set_read_chunk_size);
+ ClassDB::bind_method(D_METHOD("get_read_chunk_size"), &HTTPClient::get_read_chunk_size);
ClassDB::bind_method(D_METHOD("set_blocking_mode", "enabled"), &HTTPClient::set_blocking_mode);
ClassDB::bind_method(D_METHOD("is_blocking_mode_enabled"), &HTTPClient::is_blocking_mode_enabled);
@@ -827,6 +832,7 @@ void HTTPClient::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "blocking_mode_enabled"), "set_blocking_mode", "is_blocking_mode_enabled");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "connection", PROPERTY_HINT_RESOURCE_TYPE, "StreamPeer", 0), "set_connection", "get_connection");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "read_chunk_size", PROPERTY_HINT_RANGE, "256,16777216"), "set_read_chunk_size", "get_read_chunk_size");
BIND_ENUM_CONSTANT(METHOD_GET);
BIND_ENUM_CONSTANT(METHOD_HEAD);
diff --git a/core/io/http_client.h b/core/io/http_client.h
index 85ee1959a2..ce7fe0491b 100644
--- a/core/io/http_client.h
+++ b/core/io/http_client.h
@@ -220,6 +220,7 @@ public:
bool is_blocking_mode_enabled() const;
void set_read_chunk_size(int p_size);
+ int get_read_chunk_size() const;
Error poll();