Method: Chef::Provider::RemoteFile::HTTP#fetch

Defined in:
lib/chef/provider/remote_file/http.rb

#fetchObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/chef/provider/remote_file/http.rb', line 63

def fetch
  http = TargetIO::HTTP.new(uri, http_client_opts)
  orig_tempfile = Chef::FileContentManagement::Tempfile.new(@new_resource).tempfile
  if want_progress?
    tempfile = http.streaming_request_with_progress(uri, headers, orig_tempfile) do |size, total|
      events.resource_update_progress(new_resource, size, total, progress_interval)
    end
  else
    tempfile = http.streaming_request(uri, headers, orig_tempfile)
  end
  if tempfile
    update_cache_control_data(tempfile, http.last_response)
    tempfile.close
  else
    # cache_control shows the file is unchanged, so we got back nil from the streaming_request above, and it is
    # now our responsibility to unlink the tempfile we created
    orig_tempfile.close
    orig_tempfile.unlink
  end
  tempfile
end