From 8c81ab2c2a0ffc5694e9f5edcb09e5e262e843a9 Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Thu, 8 Dec 2022 05:43:24 -0700 Subject: [PATCH] don't invoke response block more than once due to retry If a socket error occurs while performing a streaming download via the response block provided to transport_request, avoid calling the response block again as this would result in duplicate data received by the client. fixes #86 --- lib/net/http.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/net/http.rb b/lib/net/http.rb index 8ac80a4..101a669 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -2350,7 +2350,10 @@ def transport_request(req) res } res.reading_body(@socket, req.response_body_permitted?) { - yield res if block_given? + if block_given? + count = max_retries # Don't restart in the middle of a download + yield res + end } rescue Net::OpenTimeout raise