Class: Chef::Provider::RemoteFile::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/provider/remote_file/http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, new_resource, current_resource, logger = Chef::Log.with_child) ⇒ HTTP

Parse the uri into instance variables



36
37
38
39
40
41
# File 'lib/chef/provider/remote_file/http.rb', line 36

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

Instance Attribute Details

#current_resourceObject (readonly)

Returns the value of attribute current_resource.



32
33
34
# File 'lib/chef/provider/remote_file/http.rb', line 32

def current_resource
  @current_resource
end

#loggerObject (readonly)

Returns the value of attribute logger.



33
34
35
# File 'lib/chef/provider/remote_file/http.rb', line 33

def logger
  @logger
end

#new_resourceObject (readonly)

Returns the value of attribute new_resource.



31
32
33
# File 'lib/chef/provider/remote_file/http.rb', line 31

def new_resource
  @new_resource
end

#uriObject (readonly)

Returns the value of attribute uri.



30
31
32
# File 'lib/chef/provider/remote_file/http.rb', line 30

def uri
  @uri
end

Instance Method Details

#conditional_get_headersObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/chef/provider/remote_file/http.rb', line 51

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

#eventsObject



43
44
45
# File 'lib/chef/provider/remote_file/http.rb', line 43

def events
  new_resource.events
end

#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

#headersObject



47
48
49
# File 'lib/chef/provider/remote_file/http.rb', line 47

def headers
  conditional_get_headers.merge(new_resource.headers)
end