diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp index e30d9385705d..8b0a0f8a8974 100644 --- a/scene/main/http_request.cpp +++ b/scene/main/http_request.cpp @@ -30,6 +30,7 @@ #include "http_request.h" +#include "core/io/dir_access.h" #include "core/io/file_access.h" #include "core/io/stream_peer_gzip.h" #include "core/object/callable_mp.h" @@ -204,13 +205,20 @@ void HTTPRequest::cancel_request() { } } - file.unref(); + if (file.is_valid()) { + file.unref(); + if (!download_complete) { + DirAccess::remove_absolute(download_to_file); + } + } + decompressor.unref(); client->close(); body.clear(); got_response = false; response_code = -1; request_sent = false; + download_complete = false; requesting = false; } @@ -501,6 +509,7 @@ bool HTTPRequest::_update_connection() { if (body_len >= 0) { if (downloaded.get() == body_len) { + download_complete = true; _defer_done(RESULT_SUCCESS, response_code, response_headers, body); return true; } diff --git a/scene/main/http_request.h b/scene/main/http_request.h index d51fb02079a7..af44ab8ae4b5 100644 --- a/scene/main/http_request.h +++ b/scene/main/http_request.h @@ -62,6 +62,7 @@ class HTTPRequest : public Node { private: bool requesting = false; + bool download_complete = false; String request_string; String url;