Skip to content

Commit

Permalink
fix partial body download
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-makarov authored and jasl committed Jan 12, 2021
1 parent 1cdd001 commit 1327f3c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/cocoapods-core/cdn_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def download_and_save_with_retries_async(partial_url, file_remote_url, etag, ret
path = repo + partial_url
etag_path = path.sub_ext(path.extname + '.etag')

download_impl_async(file_remote_url, etag, :context => context) do |response|
download_impl_async(file_remote_url, etag, :context => context) do |response, body|
case response.status
when 301
redirect_location = response.headers['location']
Expand All @@ -398,7 +398,6 @@ def download_and_save_with_retries_async(partial_url, file_remote_url, etag, ret
partial_url
when 200
File.open(path, 'w') do |f|
body = response.body.read
encoding = response.headers['content-encoding'].to_s
if encoding.present?
case encoding
Expand Down Expand Up @@ -475,7 +474,16 @@ def download_impl_async(file_remote_url, etag = nil, context: nil)
method.call do |task|
task.with_timeout(REQUEST_TIMEOUT) do
response = http_client.get file_remote_url, headers
yield response if block_given?

body = nil
if response.body
body = ''
while chunk = response.body.read
body << chunk
end
end

yield response, body
ensure
response&.close
end
Expand Down

0 comments on commit 1327f3c

Please sign in to comment.