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) ⇒ HTTP

Parse the uri into instance variables



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

def initialize(uri, new_resource, current_resource)
  @uri = uri
  @new_resource = new_resource
  @current_resource = current_resource
end

Instance Attribute Details

#current_resourceObject (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

#new_resourceObject (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

#uriObject (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_headersObject



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

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
  Chef::Log.debug("Cache control headers: #{cache_control_headers.inspect}")
  cache_control_headers
end

#eventsObject



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

def events
  new_resource.events
end

#fetchObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/chef/provider/remote_file/http.rb', line 62

def fetch
  http = Chef::HTTP::Simple.new(uri, http_client_opts)
  if want_progress?
    tempfile = http.streaming_request_with_progress(uri, headers) do |size, total|
      events.resource_update_progress(new_resource, size, total, progress_interval)
    end
  else
    tempfile = http.streaming_request(uri, headers)
  end
  if tempfile
    update_cache_control_data(tempfile, http.last_response)
    tempfile.close
  end
  tempfile
end

#headersObject



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

def headers
  conditional_get_headers.merge(new_resource.headers)
end