class Puppet::FileServing::HttpMetadata

Simplified metadata representation, suitable for the information that is available from HTTP headers.

Public Class Methods

new(http_response, path = '/dev/null') click to toggle source
Calls superclass method Puppet::FileServing::Metadata::new
   # File lib/puppet/file_serving/http_metadata.rb
 8 def initialize(http_response, path = '/dev/null')
 9   super(path)
10 
11   # ignore options that do not apply to HTTP metadata
12   @owner = @group = @mode = nil
13 
14   # hash available checksums for eventual collection
15   @checksums = {}
16   # use a default mtime in case there is no usable HTTP header
17   @checksums[:mtime] = "{mtime}#{Time.now}"
18 
19   # RFC-1864, deprecated in HTTP/1.1 due to partial responses
20   checksum = http_response['content-md5']
21   if checksum
22     # convert base64 digest to hex
23     checksum = checksum.unpack("m").first.unpack("H*").first
24     @checksums[:md5] = "{md5}#{checksum}"
25   end
26 
27   {
28     md5: 'X-Checksum-Md5',
29     sha1: 'X-Checksum-Sha1',
30     sha256: 'X-Checksum-Sha256'
31   }.each_pair do |checksum_type, header|
32     checksum = http_response[header]
33     if checksum
34       @checksums[checksum_type] = "{#{checksum_type}}#{checksum}"
35     end
36   end
37 
38   last_modified = http_response['last-modified']
39   if last_modified
40     mtime = DateTime.httpdate(last_modified).to_time
41     @checksums[:mtime] = "{mtime}#{mtime.utc}"
42   end
43 
44   @ftype = 'file'
45 
46   self
47 end

Public Instance Methods

collect() click to toggle source

Override of the parent class method. Does not call super! We can only return metadata that was extracted from the HTTP headers during initialize.

   # File lib/puppet/file_serving/http_metadata.rb
52 def collect
53   # Prefer the checksum_type from the indirector request options
54   # but fall back to the alternative otherwise
55   [ @checksum_type, :sha256, :sha1, :md5, :mtime ].each do |type|
56     @checksum_type = type
57     @checksum = @checksums[type]
58     break if @checksum
59   end
60 end