diff --git a/Library/Homebrew/test/download_strategies/curl_spec.rb b/Library/Homebrew/test/download_strategies/curl_spec.rb index 106eaf93bf..df5f1a3c9f 100644 --- a/Library/Homebrew/test/download_strategies/curl_spec.rb +++ b/Library/Homebrew/test/download_strategies/curl_spec.rb @@ -10,9 +10,16 @@ describe CurlDownloadStrategy do let(:version) { "1.2.3" } let(:specs) { { user: "download:123456" } } let(:artifact_domain) { nil } + let(:headers) do + { + "accept-ranges" => "bytes", + "content-length" => "37182", + } + end before do - allow(strategy).to receive(:curl_headers).and_return({ responses: [{ headers: {} }] }) + allow(strategy).to receive(:curl_headers).with(any_args) + .and_return({ responses: [{ headers: headers }] }) end it "parses the opts and sets the corresponding args" do diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index f7a34104e7..3e13097311 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -174,21 +174,20 @@ module Utils destination.dirname.mkpath if try_partial - range_stdout = curl_output("--location", "--head", *args, **options).stdout - parsed_output = parse_curl_output(range_stdout) - - headers = if parsed_output[:responses].present? - parsed_output[:responses].last[:headers] - else - {} + headers = begin + parsed_output = curl_headers(*args, **options, wanted_headers: ["accept-ranges"]) + parsed_output.fetch(:responses).last&.fetch(:headers) + rescue ErrorDuringExecution + nil end # Any value for `accept-ranges` other than none indicates that the server supports partial requests. # Its absence indicates no support. - supports_partial = headers.key?("accept-ranges") && headers["accept-ranges"] != "none" + supports_partial = headers&.key?("accept-ranges") && headers["accept-ranges"] != "none" if supports_partial && destination.exist? && + headers&.key?("content-length") && destination.size == headers["content-length"].to_i return # We've already downloaded all the bytes end