Time out requests the server never answers

HTTPRequest has no timeout by default, so a server that accepts the
connection but never responds left song downloads waiting forever.
Requests now fail after 120 seconds, which triggers the normal retry.
This commit is contained in:
Sansan committed 2026-10-06 08:32:56 +02:00
1 parent 1acc757981
commit 5a979fca48
3 files changed
+56 -2

No files matched your search

+7 -2
View File
@@ -4,6 +4,10 @@ extends RefCounted
##
## Tests subclass this to answer requests without a network connection.
## Seconds before a request is given up and reported as failed. This covers the whole
## download, so it is generous enough for long songs on a slow connection.
var timeout_seconds: float = 120.0
var _owner: Node
@@ -12,10 +16,11 @@ func _init(owner: Node) -> void:
## Requests [param url] and calls [param on_complete] with
## [code](response_code: int, body: PackedByteArray)[/code]. Connection errors are
## reported with response code 0.
## [code](response_code: int, body: PackedByteArray)[/code]. Connection errors and
## timeouts are reported with response code 0.
func request(url: String, method: int, on_complete: Callable) -> void:
var http_request: HTTPRequest = HTTPRequest.new()
http_request.timeout = timeout_seconds
_owner.add_child(http_request)
http_request.request_completed.connect(
func(