My original answer contributed to passing the block to RestClient::Request#execute , but it only passed data to the block after the full answer was read. Thus, exercise is futile. Here's how to do it:
File.open('/tmp/foo.iso', 'w') {|f| block = proc { |response| response.read_body do |chunk| puts "Working on response" f.write chunk end } RestClient::Request.new(method: :get, url: 'http://mirror.pnl.gov/releases/xenial/ubuntu-16.04-server-amd64.iso', block_response: block).execute }
This is due to the problem of the client-client project .
Note. redirection does not work in this mode, and also you lose HTTP exit status, cookies, headers, etc. Hope this will be fixed some day.
source share