Skip to content

Commit

Permalink
Merge pull request godotengine#49226 from Faless/net/4.x_empty_chunk_fix
Browse files Browse the repository at this point in the history
[Net] Fix HTTPRquest store_buffer error.
  • Loading branch information
akien-mga authored May 31, 2021
2 parents afe1d16 + 507a9be commit ff648e2
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions scene/main/http_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ff648e2

Please sign in to comment.