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
 7 def initialize(http_response, path = '/dev/null')
 8   super(path)
 9 
10   # ignore options that do not apply to HTTP metadata
11   @owner = @group = @mode = nil
12 
13   # hash available checksums for eventual collection
14   @checksums = {}
15   # use a default mtime in case there is no usable HTTP header
16   @checksums[:mtime] = "{mtime}#{Time.now}"
17 
18   # RFC-1864, deprecated in HTTP/1.1 due to partial responses
19   checksum = http_response['content-md5']
20   if checksum
21     # convert base64 digest to hex
22     checksum = checksum.unpack("m").first.unpack("H*").first
23     @checksums[:md5] = "{md5}#{checksum}"
24   end
25 
26   {
27     md5: 'X-Checksum-Md5',
28     sha1: 'X-Checksum-Sha1',
29     sha256: 'X-Checksum-Sha256'
30   }.each_pair do |checksum_type, header|
31     checksum = http_response[header]
32     if checksum
33       @checksums[checksum_type] = "{#{checksum_type}}#{checksum}"
34     end
35   end
36 
37   last_modified = http_response['last-modified']
38   if last_modified
39     mtime = DateTime.httpdate(last_modified).to_time
40     @checksums[:mtime] = "{mtime}#{mtime.utc}"
41   end
42 
43   @ftype = 'file'
44 
45   self
46 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
51 def collect
52   # Prefer the checksum_type from the indirector request options
53   # but fall back to the alternative otherwise
54   [ @checksum_type, :sha256, :sha1, :md5, :mtime ].each do |type|
55     @checksum_type = type
56     @checksum = @checksums[type]
57     break if @checksum
58   end
59 end