From d21ac4f0caf070d41c9fbebe730025d53e6c3e97 Mon Sep 17 00:00:00 2001 From: Yauheni Kryudziuk Date: Tue, 20 Aug 2013 11:50:54 +0200 Subject: [PATCH] Allow passing Content-Disposition header when saving file into Openstack cloud --- lib/fog/openstack/models/storage/file.rb | 2 ++ tests/openstack/models/storage/file_tests.rb | 21 +++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/fog/openstack/models/storage/file.rb b/lib/fog/openstack/models/storage/file.rb index 53fdffacb..0cd5e8d9d 100644 --- a/lib/fog/openstack/models/storage/file.rb +++ b/lib/fog/openstack/models/storage/file.rb @@ -10,6 +10,7 @@ module Fog attribute :content_length, :aliases => ['bytes', 'Content-Length'], :type => :integer attribute :content_type, :aliases => ['content_type', 'Content-Type'] + attribute :content_disposition, :aliases => ['content_disposition', 'Content-Disposition'] attribute :etag, :aliases => ['hash', 'Etag'] attribute :last_modified, :aliases => ['last_modified', 'Last-Modified'], :type => :time attribute :access_control_allow_origin, :aliases => ['Access-Control-Allow-Origin'] @@ -72,6 +73,7 @@ module Fog def save(options = {}) requires :body, :directory, :key options['Content-Type'] = content_type if content_type + options['Content-Disposition'] = content_disposition if content_disposition options['Access-Control-Allow-Origin'] = access_control_allow_origin if access_control_allow_origin options['Origin'] = origin if origin options.merge!(metadata_to_headers) diff --git a/tests/openstack/models/storage/file_tests.rb b/tests/openstack/models/storage/file_tests.rb index 0b3e61752..5daf228f3 100644 --- a/tests/openstack/models/storage/file_tests.rb +++ b/tests/openstack/models/storage/file_tests.rb @@ -2,6 +2,10 @@ Shindo.tests('Fog::OpenStack::Storage | file', ['openstack']) do pending if Fog.mocking? + def object_attributes(file=@instance) + @instance.service.head_object(@directory.key, file.key).headers + end + def object_meta_attributes @instance.service.head_object(@directory.key, @instance.key).headers.reject {|k, v| !(k =~ /X-Object-Meta-/)} end @@ -67,7 +71,22 @@ Shindo.tests('Fog::OpenStack::Storage | file', ['openstack']) do end end - + + tests('#content_disposition') do + before do + @instance = @directory.files.create :key => 'meta-test', :body => lorem_file, :content_disposition => 'ho-ho-ho' + end + + after do + clear_metadata + @instance.save + end + + tests("sets Content-Disposition on create").returns("ho-ho-ho") do + object_attributes(@instance)["Content-Disposition"] + end + end + tests('#metadata keys') do after do