Class: Chef::Provider::RemoteFile::HTTP
- Inherits:
-
Object
- Object
- Chef::Provider::RemoteFile::HTTP
- Defined in:
- lib/chef/provider/remote_file/http.rb
Instance Attribute Summary collapse
-
#current_resource ⇒ Object
readonly
Returns the value of attribute current_resource.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#new_resource ⇒ Object
readonly
Returns the value of attribute new_resource.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #conditional_get_headers ⇒ Object
- #events ⇒ Object
- #fetch ⇒ Object
- #headers ⇒ Object
-
#initialize(uri, new_resource, current_resource, logger = Chef::Log.with_child) ⇒ HTTP
constructor
Parse the uri into instance variables.
Constructor Details
#initialize(uri, new_resource, current_resource, logger = Chef::Log.with_child) ⇒ HTTP
Parse the uri into instance variables
37 38 39 40 41 42 |
# 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 |
Instance Attribute Details
#current_resource ⇒ Object (readonly)
Returns the value of attribute current_resource.
33 34 35 |
# File 'lib/chef/provider/remote_file/http.rb', line 33 def current_resource @current_resource end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
34 35 36 |
# File 'lib/chef/provider/remote_file/http.rb', line 34 def logger @logger end |
#new_resource ⇒ Object (readonly)
Returns the value of attribute new_resource.
32 33 34 |
# File 'lib/chef/provider/remote_file/http.rb', line 32 def new_resource @new_resource end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
31 32 33 |
# File 'lib/chef/provider/remote_file/http.rb', line 31 def uri @uri end |
Instance Method Details
#conditional_get_headers ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# 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 ⇒ Object
44 45 46 |
# File 'lib/chef/provider/remote_file/http.rb', line 44 def events new_resource.events end |
#fetch ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# 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 ⇒ Object
48 49 50 |
# File 'lib/chef/provider/remote_file/http.rb', line 48 def headers conditional_get_headers.merge(new_resource.headers) end |