File: head_object.rb

package info (click to toggle)
ruby-fog-aws 3.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,140 kB
  • sloc: ruby: 73,328; javascript: 14; makefile: 9; sh: 4
file content (62 lines) | stat: -rw-r--r-- 2,799 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
module Fog
  module AWS
    class Storage
      class Real
        # Get headers for an object from S3
        #
        # @param bucket_name [String] Name of bucket to read from
        # @param object_name [String] Name of object to read
        # @param options [Hash]:
        # @option options [String] If-Match Returns object only if its etag matches this value, otherwise returns 412 (Precondition Failed).
        # @option options [Time]   If-Modified-Since Returns object only if it has been modified since this time, otherwise returns 304 (Not Modified).
        # @option options [String] If-None-Match Returns object only if its etag differs from this value, otherwise returns 304 (Not Modified)
        # @option options [Time]   If-Unmodified-Since Returns object only if it has not been modified since this time, otherwise returns 412 (Precodition Failed).
        # @option options [String] Range Range of object to download
        # @option options [String] versionId specify a particular version to retrieve
        #
        # @return [Excon::Response] response:
        #   * body [String] Contents of object
        #   * headers [Hash]:
        #     * Content-Length [String] - Size of object contents
        #     * Content-Type [String] - MIME type of object
        #     * ETag [String] - Etag of object
        #     * Last-Modified - [String] Last modified timestamp for object
        #
        # @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectHEAD.html
        #
        def head_object(bucket_name, object_name, options={})
          unless bucket_name
            raise ArgumentError.new('bucket_name is required')
          end
          unless object_name
            raise ArgumentError.new('object_name is required')
          end
          if version_id = options.delete('versionId')
            query = {'versionId' => version_id}
          end
          headers = {}
          headers['If-Modified-Since'] = Fog::Time.at(options['If-Modified-Since'].to_i).to_date_header if options['If-Modified-Since']
          headers['If-Unmodified-Since'] = Fog::Time.at(options['If-Unmodified-Since'].to_i).to_date_header if options['If-Modified-Since']
          headers.merge!(options)
          request({
            :expects    => 200,
            :headers    => headers,
            :bucket_name => bucket_name,
            :object_name => object_name,
            :idempotent => true,
            :method     => 'HEAD',
            :query      => query
          })
        end
      end

      class Mock # :nodoc:all
        def head_object(bucket_name, object_name, options = {})
          response = get_object(bucket_name, object_name, options)
          response.body = nil
          response
        end
      end
    end
  end
end