2010-03-13 13:37:24 -08:00
|
|
|
module Fog
|
2011-06-15 14:26:43 -07:00
|
|
|
module Storage
|
|
|
|
class AWS
|
2010-03-13 13:37:24 -08:00
|
|
|
class Real
|
2009-08-08 14:46:13 -07:00
|
|
|
|
|
|
|
# Get headers for an object from S3
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * bucket_name<~String> - Name of bucket to read from
|
|
|
|
# * object_name<~String> - Name of object to read
|
|
|
|
# * options<~Hash>:
|
|
|
|
# * 'If-Match'<~String> - Returns object only if its etag matches this value, otherwise returns 412 (Precondition Failed).
|
|
|
|
# * 'If-Modified-Since'<~Time> - Returns object only if it has been modified since this time, otherwise returns 304 (Not Modified).
|
|
|
|
# * 'If-None-Match'<~String> - Returns object only if its etag differs from this value, otherwise returns 304 (Not Modified)
|
|
|
|
# * 'If-Unmodified-Since'<~Time> - Returns object only if it has not been modified since this time, otherwise returns 412 (Precodition Failed).
|
|
|
|
# * 'Range'<~String> - Range of object to download
|
2010-05-10 20:28:27 -07:00
|
|
|
# * 'versionId'<~String> - specify a particular version to retrieve
|
2009-08-08 14:46:13 -07:00
|
|
|
#
|
|
|
|
# ==== Returns
|
2009-11-02 18:48:49 -08:00
|
|
|
# * response<~Excon::Response>:
|
2009-08-08 14:46:13 -07:00
|
|
|
# * 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
|
2010-10-29 18:05:59 -07:00
|
|
|
#
|
|
|
|
# ==== See Also
|
|
|
|
# http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectHEAD.html
|
|
|
|
|
2009-08-08 14:46:13 -07:00
|
|
|
def head_object(bucket_name, object_name, options={})
|
2010-05-14 12:37:28 -07:00
|
|
|
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')
|
2010-06-05 14:19:39 -07:00
|
|
|
query = {'versionId' => version_id}
|
2010-05-14 12:37:28 -07:00
|
|
|
end
|
2009-08-08 14:46:13 -07:00
|
|
|
headers = {}
|
2011-01-28 15:33:35 -08:00
|
|
|
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']
|
2009-08-08 14:46:13 -07:00
|
|
|
headers.merge!(options)
|
|
|
|
request({
|
2012-02-14 18:58:20 -06:00
|
|
|
:expects => 200,
|
|
|
|
:headers => headers,
|
|
|
|
:host => "#{bucket_name}.#{@host}",
|
|
|
|
:idempotent => true,
|
|
|
|
:method => 'HEAD',
|
|
|
|
:path => CGI.escape(object_name),
|
|
|
|
:query => query
|
2009-08-08 14:46:13 -07:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2009-07-13 19:14:59 -07:00
|
|
|
end
|
|
|
|
|
2010-10-29 18:16:36 -07:00
|
|
|
class Mock # :nodoc:all
|
2009-08-08 14:46:13 -07:00
|
|
|
|
|
|
|
def head_object(bucket_name, object_name, options = {})
|
|
|
|
response = get_object(bucket_name, object_name, options)
|
|
|
|
response.body = nil
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-07-13 19:14:59 -07:00
|
|
|
end
|
|
|
|
end
|
2010-03-13 13:37:24 -08:00
|
|
|
end
|