Class: S3::ObjectHeadRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/s3/object_head_request.rb

Constant Summary

Constants inherited from Request

Request::AWS_ALGORITHM, Request::AWS_REQUEST, Request::SERVICE, Request::UNSIGNED_PAYLOAD

Instance Method Summary collapse

Methods inherited from Request

#initialize

Constructor Details

This class inherits a constructor from S3::Request

Instance Method Details

#parse_response(response) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/s3/object_head_request.rb', line 16

def parse_response( response )
   = {}
  response.headers.each do | header_name, header_value |
    if header_name.downcase.start_with?( 'x-amz-meta-' )
      meta_key = header_name.sub( /^x-amz-meta-/i, '' )
      [ meta_key ] = header_value
    end
  end

  { content_type: response.headers[ 'content-type' ],
    content_length: response.headers[ 'content-length' ]&.to_i,
    last_modified: Helpers.parse_iso8601( response.headers[ 'last-modified' ] ),
    etag: response.headers[ 'etag' ]&.tr( '"', '' ),
    storage_class: response.headers[ 'x-amz-storage-class' ],
    version_id: response.headers[ 'x-amz-version-id' ],
    metadata: 
  }
end

#submit(bucket:, key:) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/s3/object_head_request.rb', line 3

def submit( bucket:, key: )
  path = "/#{ bucket }/#{ Helpers.encode_key( key ) }"
  response = head( path )

  if response.status == 404
    ResponseMethods.install( response, nil )
  else
    build_result( response, ObjectHeadResult ) do
      ObjectHeadResult.new( parse_response( response ) )
    end
  end
end