Skip to content

Instantly share code, notes, and snippets.

@hjkp
Created October 10, 2008 20:25
Show Gist options
  • Save hjkp/16150 to your computer and use it in GitHub Desktop.
Save hjkp/16150 to your computer and use it in GitHub Desktop.
res = nil
tf = nil
http.request(req) do |response|
if raw
tf = Tempfile.new("chef-rest")
# Stolen from http://www.ruby-forum.com/topic/166423
# Kudos to _why!
size, total = 0, response.header['Content-Length'].to_i
response.read_body do |chunk|
tf.write(chunk)
size += chunk.size
Chef::Log.debug("#{req.path} %d%% done (%d of %d)" % [(size * 100) / total, size, total])
end
tf.close
tf
else
response.read_body
end
res = response
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment