class Chef::Provider::RemoteFile::HTTP
Attributes
current_resource[R]
logger[R]
new_resource[R]
uri[R]
Public Class Methods
new(uri, new_resource, current_resource, logger = Chef::Log.with_child)
click to toggle source
Parse the uri into instance variables
# File lib/chef/provider/remote_file/http.rb, line 37 def initialize(uri, new_resource, current_resource, logger = Chef::Log.with_child) @uri = uri @new_resource = new_resource @current_resource = current_resource @logger = logger end
Public Instance Methods
conditional_get_headers()
click to toggle source
# File lib/chef/provider/remote_file/http.rb, line 52 def conditional_get_headers cache_control_headers = {} if (last_modified = cache_control_data.mtime) && want_mtime_cache_control? cache_control_headers["if-modified-since"] = last_modified end if (etag = cache_control_data.etag) && want_etag_cache_control? cache_control_headers["if-none-match"] = etag end logger.trace("Cache control headers: #{cache_control_headers.inspect}") cache_control_headers end
events()
click to toggle source
# File lib/chef/provider/remote_file/http.rb, line 44 def events new_resource.events end
fetch()
click to toggle source
# File lib/chef/provider/remote_file/http.rb, line 64 def fetch http = Chef::HTTP::Simple.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
headers()
click to toggle source
# File lib/chef/provider/remote_file/http.rb, line 48 def headers conditional_get_headers.merge(new_resource.headers) end
Private Instance Methods
cache_control_data()
click to toggle source
# File lib/chef/provider/remote_file/http.rb, line 95 def cache_control_data @cache_control_data ||= CacheControlData.load_and_validate(uri, current_resource.checksum) end
etag_from(response)
click to toggle source
# File lib/chef/provider/remote_file/http.rb, line 119 def etag_from(response) response["etag"] end
http_client_opts()
click to toggle source
# File lib/chef/provider/remote_file/http.rb, line 123 def http_client_opts opts = {} # CHEF-3140 # 1. If it's already compressed, trying to compress it more will # probably be counter-productive. # 2. Some servers are misconfigured so that you GET $URL/file.tgz but # they respond with content type of tar and content encoding of gzip, # which tricks Chef::REST into decompressing the response body. In this # case you'd end up with a tar archive (no gzip) named, e.g., foo.tgz, # which is not what you wanted. if uri.to_s =~ /gz$/ logger.trace("Turning gzip compression off due to filename ending in gz") opts[:disable_gzip] = true end opts end
last_modified_time_from(response)
click to toggle source
# File lib/chef/provider/remote_file/http.rb, line 115 def last_modified_time_from(response) response["last_modified"] || response["date"] end
progress_interval()
click to toggle source
# File lib/chef/provider/remote_file/http.rb, line 103 def progress_interval Chef::Config[:download_progress_interval] end
update_cache_control_data(tempfile, response)
click to toggle source
# File lib/chef/provider/remote_file/http.rb, line 88 def update_cache_control_data(tempfile, response) cache_control_data.checksum = Chef::Digester.checksum_for_file(tempfile.path) cache_control_data.mtime = last_modified_time_from(response) cache_control_data.etag = etag_from(response) cache_control_data.save end
want_etag_cache_control?()
click to toggle source
# File lib/chef/provider/remote_file/http.rb, line 111 def want_etag_cache_control? new_resource.use_etag end
want_mtime_cache_control?()
click to toggle source
# File lib/chef/provider/remote_file/http.rb, line 107 def want_mtime_cache_control? new_resource.use_last_modified end
want_progress?()
click to toggle source
# File lib/chef/provider/remote_file/http.rb, line 99 def want_progress? events.formatter? && (Chef::Config[:show_download_progress] || !!new_resource.show_progress) end