summaryrefslogtreecommitdiff
path: root/scene/main
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 /scene/main
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 'scene/main')
-rw-r--r--scene/main/http_request.cpp16
-rw-r--r--scene/main/http_request.h3
2 files changed, 19 insertions, 0 deletions
diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp
index 6c922adbd2..0ae330b2ed 100644
--- a/scene/main/http_request.cpp
+++ b/scene/main/http_request.cpp
@@ -457,6 +457,18 @@ String HTTPRequest::get_download_file() const {
return download_to_file;
}
+
+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();
+}
+
HTTPClient::Status HTTPRequest::get_http_client_status() const {
return client->get_status();
}
@@ -524,9 +536,13 @@ void HTTPRequest::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_timeout", "timeout"), &HTTPRequest::set_timeout);
ClassDB::bind_method(D_METHOD("get_timeout"), &HTTPRequest::get_timeout);
+ ClassDB::bind_method(D_METHOD("set_download_chunk_size"), &HTTPRequest::set_download_chunk_size);
+ ClassDB::bind_method(D_METHOD("get_download_chunk_size"), &HTTPRequest::get_download_chunk_size);
+
ClassDB::bind_method(D_METHOD("_timeout"), &HTTPRequest::_timeout);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "download_file", PROPERTY_HINT_FILE), "set_download_file", "get_download_file");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "download_chunk_size", PROPERTY_HINT_RANGE, "256,16777216"), "set_download_chunk_size", "get_download_chunk_size");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_threads"), "set_use_threads", "is_using_threads");
ADD_PROPERTY(PropertyInfo(Variant::INT, "body_size_limit", PROPERTY_HINT_RANGE, "-1,2000000000"), "set_body_size_limit", "get_body_size_limit");
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_redirects", PROPERTY_HINT_RANGE, "-1,64"), "set_max_redirects", "get_max_redirects");
diff --git a/scene/main/http_request.h b/scene/main/http_request.h
index f1f91235a6..fa01172d9f 100644
--- a/scene/main/http_request.h
+++ b/scene/main/http_request.h
@@ -126,6 +126,9 @@ public:
void set_download_file(const String &p_file);
String get_download_file() const;
+ void set_download_chunk_size(int p_chunk_size);
+ int get_download_chunk_size() const;
+
void set_body_size_limit(int p_bytes);
int get_body_size_limit() const;