Skip to content

Commit

Permalink
[storage] better behavior related to headers
Browse files Browse the repository at this point in the history
  • Loading branch information
geemus committed Nov 9, 2010
1 parent e3a75d9 commit 070e256
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 30 deletions.
32 changes: 20 additions & 12 deletions lib/fog/aws/models/storage/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ class File < Fog::Model
identity :key, :aliases => 'Key'

attr_writer :body
attribute :content_length, :aliases => ['Content-Length', 'Size'], :type => :integer
attribute :content_type, :aliases => 'Content-Type'
attribute :etag, :aliases => ['Etag', 'ETag']
attribute :last_modified, :aliases => ['Last-Modified', 'LastModified'], :type => :time
attribute :owner, :aliases => 'Owner'
attribute :storage_class, :aliases => 'StorageClass'
attribute :cache_control, :aliases => 'Cache-Control'
attribute :content_disposition, :aliases => 'Content-Disposition'
attribute :content_encoding, :aliases => 'Content-Encoding'
attribute :content_length, :aliases => ['Content-Length', 'Size'], :type => :integer
attribute :content_md5, :aliases => 'Content-MD5'
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)
valid_acls = ['private', 'public-read', 'public-read-write', 'authenticated-read']
Expand Down Expand Up @@ -82,12 +87,15 @@ def save(options = {})
if options != {}
Formatador.display_line("[yellow][WARN] options param is deprecated, use acl= instead[/] [light_black](#{caller.first})[/]")
end
if @acl
options['x-amz-acl'] ||= @acl
end
if content_type
options['Content-Type'] = content_type
end
options['x-amz-acl'] ||= @acl if @acl
options['Cache-Control'] = cache_control if cache_control
options['Content-Disposition'] = content_disposition if content_disposition
options['Content-Encoding'] = content_encoding if content_encoding
options['Content-MD5'] = content_md5 if content_md5
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)
@etag = data.headers['ETag']
true
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/aws/models/storage/files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get(key, options = {}, &block)
:key => key
}
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
end
end
Expand All @@ -67,7 +67,7 @@ def head(key, options = {})
:key => key
}
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
end
end
Expand Down
31 changes: 19 additions & 12 deletions lib/fog/google/models/storage/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ class File < Fog::Model
identity :key, :aliases => 'Key'

attr_writer :body
attribute :content_length, :aliases => ['Content-Length', 'Size'], :type => :integer
attribute :content_type, :aliases => 'Content-Type'
attribute :etag, :aliases => ['Etag', 'ETag']
attribute :last_modified, :aliases => ['Last-Modified', 'LastModified'], :type => :time
attribute :owner, :aliases => 'Owner'
attribute :storage_class, :aliases => 'StorageClass'
attribute :cache_control, :aliases => 'Cache-Control'
attribute :content_disposition, :aliases => 'Content-Disposition'
attribute :content_encoding, :aliases => 'Content-Encoding'
attribute :content_length, :aliases => ['Content-Length', 'Size'], :type => :integer
attribute :content_md5, :aliases => 'Content-MD5'
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)
valid_acls = ['private', 'public-read', 'public-read-write', 'authenticated-read']
Expand Down Expand Up @@ -85,12 +90,14 @@ def save(options = {})
if options != {}
Formatador.display_line("[yellow][WARN] options param is deprecated, use acl= instead[/] [light_black](#{caller.first})[/]")
end
if @acl
options['x-goog-acl'] ||= @acl
end
if content_type
options['Content-Type'] = content_type
end
options['x-goog-acl'] ||= @acl if @acl
options['Cache-Control'] = cache_control if cache_control
options['Content-Disposition'] = content_disposition if content_disposition
options['Content-Encoding'] = content_encoding if content_encoding
options['Content-MD5'] = content_md5 if content_md5
options['Content-Type'] = content_type if content_type
options['Expires'] = expires if expires

data = connection.put_object(directory.key, @key, @body, options)
@etag = data.headers['ETag']
true
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/google/models/storage/files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get(key, options = {}, &block)
:key => key
}
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
end
end
Expand All @@ -67,7 +67,7 @@ def head(key, options = {})
:key => key
}
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
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/rackspace/models/storage/files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get(key, &block)
:key => key
}
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
end
end
Expand All @@ -62,7 +62,7 @@ def head(key, options = {})
data = connection.head_object(directory.name, key, options)
file_data = { :key => key }
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
end
end
Expand Down

0 comments on commit 070e256

Please sign in to comment.