1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[storage] better behavior related to headers

This commit is contained in:
geemus 2010-11-08 17:14:21 -08:00
parent e3a75d9883
commit 070e2565d3
5 changed files with 45 additions and 30 deletions

View file

@ -12,12 +12,17 @@ module Fog
identity :key, :aliases => 'Key' identity :key, :aliases => 'Key'
attr_writer :body attr_writer :body
attribute :content_length, :aliases => ['Content-Length', 'Size'], :type => :integer attribute :cache_control, :aliases => 'Cache-Control'
attribute :content_type, :aliases => 'Content-Type' attribute :content_disposition, :aliases => 'Content-Disposition'
attribute :etag, :aliases => ['Etag', 'ETag'] attribute :content_encoding, :aliases => 'Content-Encoding'
attribute :last_modified, :aliases => ['Last-Modified', 'LastModified'], :type => :time attribute :content_length, :aliases => ['Content-Length', 'Size'], :type => :integer
attribute :owner, :aliases => 'Owner' attribute :content_md5, :aliases => 'Content-MD5'
attribute :storage_class, :aliases => 'StorageClass' attribute :content_type, :aliases => 'Content-Type'
attribute :etag, :aliases => ['Etag', 'ETag']
attribute :expires, :aliases => 'Expires'
attribute :last_modified, :aliases => ['Last-Modified', 'LastModified'], :type => :time
attribute :owner, :aliases => 'Owner'
attribute :storage_class, :aliases => ['x-amz-storage-class', 'StorageClass']
def acl=(new_acl) def acl=(new_acl)
valid_acls = ['private', 'public-read', 'public-read-write', 'authenticated-read'] valid_acls = ['private', 'public-read', 'public-read-write', 'authenticated-read']
@ -82,12 +87,15 @@ module Fog
if options != {} if options != {}
Formatador.display_line("[yellow][WARN] options param is deprecated, use acl= instead[/] [light_black](#{caller.first})[/]") Formatador.display_line("[yellow][WARN] options param is deprecated, use acl= instead[/] [light_black](#{caller.first})[/]")
end end
if @acl options['x-amz-acl'] ||= @acl if @acl
options['x-amz-acl'] ||= @acl options['Cache-Control'] = cache_control if cache_control
end options['Content-Disposition'] = content_disposition if content_disposition
if content_type options['Content-Encoding'] = content_encoding if content_encoding
options['Content-Type'] = content_type options['Content-MD5'] = content_md5 if content_md5
end options['Content-Type'] = content_type if content_type
options['Expires'] = expires if expires
options['x-amz-storage-class'] = storage_class if storage_class
data = connection.put_object(directory.key, @key, @body, options) data = connection.put_object(directory.key, @key, @body, options)
@etag = data.headers['ETag'] @etag = data.headers['ETag']
true true

View file

@ -46,7 +46,7 @@ module Fog
:key => key :key => key
} }
for key, value in data.headers for key, value in data.headers
if ['Content-Length', 'Content-Type', 'ETag', 'Last-Modified'].include?(key) if model.aliases.include?(key)
file_data[key] = value file_data[key] = value
end end
end end
@ -67,7 +67,7 @@ module Fog
:key => key :key => key
} }
for key, value in data.headers for key, value in data.headers
if ['Content-Length', 'Content-Type', 'ETag', 'Last-Modified'].include?(key) if model.aliases.include?(key)
file_data[key] = value file_data[key] = value
end end
end end

View file

@ -12,12 +12,17 @@ module Fog
identity :key, :aliases => 'Key' identity :key, :aliases => 'Key'
attr_writer :body attr_writer :body
attribute :content_length, :aliases => ['Content-Length', 'Size'], :type => :integer attribute :cache_control, :aliases => 'Cache-Control'
attribute :content_type, :aliases => 'Content-Type' attribute :content_disposition, :aliases => 'Content-Disposition'
attribute :etag, :aliases => ['Etag', 'ETag'] attribute :content_encoding, :aliases => 'Content-Encoding'
attribute :last_modified, :aliases => ['Last-Modified', 'LastModified'], :type => :time attribute :content_length, :aliases => ['Content-Length', 'Size'], :type => :integer
attribute :owner, :aliases => 'Owner' attribute :content_md5, :aliases => 'Content-MD5'
attribute :storage_class, :aliases => 'StorageClass' attribute :content_type, :aliases => 'Content-Type'
attribute :etag, :aliases => ['Etag', 'ETag']
attribute :expires, :aliases => 'Expires'
attribute :last_modified, :aliases => ['Last-Modified', 'LastModified'], :type => :time
attribute :owner, :aliases => 'Owner'
attribute :storage_class, :aliases => ['x-goog-storage-class', 'StorageClass']
def acl=(new_acl) def acl=(new_acl)
valid_acls = ['private', 'public-read', 'public-read-write', 'authenticated-read'] valid_acls = ['private', 'public-read', 'public-read-write', 'authenticated-read']
@ -85,12 +90,14 @@ module Fog
if options != {} if options != {}
Formatador.display_line("[yellow][WARN] options param is deprecated, use acl= instead[/] [light_black](#{caller.first})[/]") Formatador.display_line("[yellow][WARN] options param is deprecated, use acl= instead[/] [light_black](#{caller.first})[/]")
end end
if @acl options['x-goog-acl'] ||= @acl if @acl
options['x-goog-acl'] ||= @acl options['Cache-Control'] = cache_control if cache_control
end options['Content-Disposition'] = content_disposition if content_disposition
if content_type options['Content-Encoding'] = content_encoding if content_encoding
options['Content-Type'] = content_type options['Content-MD5'] = content_md5 if content_md5
end options['Content-Type'] = content_type if content_type
options['Expires'] = expires if expires
data = connection.put_object(directory.key, @key, @body, options) data = connection.put_object(directory.key, @key, @body, options)
@etag = data.headers['ETag'] @etag = data.headers['ETag']
true true

View file

@ -46,7 +46,7 @@ module Fog
:key => key :key => key
} }
for key, value in data.headers for key, value in data.headers
if ['Content-Length', 'Content-Type', 'ETag', 'Last-Modified'].include?(key) if model.aliases.include?(key)
file_data[key] = value file_data[key] = value
end end
end end
@ -67,7 +67,7 @@ module Fog
:key => key :key => key
} }
for key, value in data.headers for key, value in data.headers
if ['Content-Length', 'Content-Type', 'ETag', 'Last-Modified'].include?(key) if model.aliases.include?(key)
file_data[key] = value file_data[key] = value
end end
end end

View file

@ -43,7 +43,7 @@ module Fog
:key => key :key => key
} }
for key, value in data.headers for key, value in data.headers
if ['Content-Length', 'Content-Type', 'ETag', 'Last-Modified'].include?(key) if model.aliases.include?(key)
file_data[key] = value file_data[key] = value
end end
end end
@ -62,7 +62,7 @@ module Fog
data = connection.head_object(directory.name, key, options) data = connection.head_object(directory.name, key, options)
file_data = { :key => key } file_data = { :key => key }
for key, value in data.headers for key, value in data.headers
if ['Content-Length', 'Content-Type', 'ETag', 'Last-Modified'].include?(key) if model.aliases.include?(key)
file_data[key] = value file_data[key] = value
end end
end end