summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-05-31 15:42:31 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-05-31 15:42:31 +0200
commit507a9beca1bf70f60d0cf1e2095ae81e5200dbe1 (patch)
tree1a61a2568eea0bcb45feca367d29facee5172702
parentafe1d1672f309c9e04984bf8faee489851fa26e4 (diff)
[Net] Fix HTTPRquest store_buffer error.
HTTPRquest no longer call store_buffer/append_array when the chunk size is 0.
-rw-r--r--scene/main/http_request.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp
index 884696d58d..927b114fbc 100644
--- a/scene/main/http_request.cpp
+++ b/scene/main/http_request.cpp
@@ -375,17 +375,19 @@ bool HTTPRequest::_update_connection() {
}
PackedByteArray chunk = client->read_response_body_chunk();
- downloaded.add(chunk.size());
- if (file) {
- const uint8_t *r = chunk.ptr();
- file->store_buffer(r, chunk.size());
- if (file->get_error() != OK) {
- call_deferred("_request_done", RESULT_DOWNLOAD_FILE_WRITE_ERROR, response_code, response_headers, PackedByteArray());
- return true;
+ if (chunk.size()) {
+ downloaded.add(chunk.size());
+ if (file) {
+ const uint8_t *r = chunk.ptr();
+ file->store_buffer(r, chunk.size());
+ if (file->get_error() != OK) {
+ call_deferred("_request_done", RESULT_DOWNLOAD_FILE_WRITE_ERROR, response_code, response_headers, PackedByteArray());
+ return true;
+ }
+ } else {
+ body.append_array(chunk);
}
- } else {
- body.append_array(chunk);
}
if (body_size_limit >= 0 && downloaded.get() > body_size_limit) {