diff --git a/lib/fog/hp/requests/storage/post_container.rb b/lib/fog/hp/requests/storage/post_container.rb index a161e7acd..ac213ca85 100644 --- a/lib/fog/hp/requests/storage/post_container.rb +++ b/lib/fog/hp/requests/storage/post_container.rb @@ -3,17 +3,17 @@ module Fog class HP class Real - # Update or create a container + # Create or update metadata for an existing container # # ==== Parameters - # * container<~String> - Name for container, should be < 256 bytes and must not contain '/' - # + # * container<~String> - Name for existing container, should be < 256 bytes and must not contain '/' + # * headers<~Hash> - Hash of metadata name/value pairs def post_container(container, headers = {}) response = request( :expects => 204, :headers => headers, :method => 'POST', - :path => "#{Fog::HP.escape(container)}" + :path => Fog::HP.escape(container) ) response end @@ -22,7 +22,7 @@ module Fog class Mock # :nodoc:all - def post_container(container_name, object_name, headers = {}) + def post_container(container_name, headers = {}) if self.data[:containers][container_name].nil? raise Fog::Storage::HP::NotFound end diff --git a/lib/fog/hp/requests/storage/post_object.rb b/lib/fog/hp/requests/storage/post_object.rb index a0a71c280..9183a774a 100644 --- a/lib/fog/hp/requests/storage/post_object.rb +++ b/lib/fog/hp/requests/storage/post_object.rb @@ -3,11 +3,12 @@ module Fog class HP class Real - # Create a new object + # Create or update metadata for an existing object # # ==== Parameters - # * container<~String> - Name for container, should be < 256 bytes and must not contain '/' - # + # * container<~String> - Name of the existing container, should be < 256 bytes and must not contain '/' + # * object<~String> - Name of the existing object + # * headers<~Hash> - Hash of metadata name/value pairs def post_object(container, object, headers = {}) response = request( :expects => 202, @@ -24,17 +25,24 @@ module Fog def post_object(container_name, object_name, headers = {}) response = Excon::Response.new - source_container = self.data[:containers][container_name] - container = self.data[:containers][container_name] - if (source_container && container) + if container = self.data[:containers][container_name] response.status = 202 - source_object = source_container[:objects][object_name] - target_object = source_object.dup - target_object.merge!({ - 'Key' => object_name, - 'Date' => Fog::Time.now.to_date_header - }) - container[:objects][object_name] = target_object + object = container[:objects][object_name] + + for key, value in headers + case key + when 'Content-Disposition', 'Content-Encoding', 'X-Delete-At', 'X-Delete-After', /^X-Object-Meta-/ + object[key] = value unless value.nil? + end + end + + container[:objects][object_name] = object + response.headers = { + 'Content-Length' => object['Content-Length'], + 'Content-Type' => object['Content-Type'], + 'ETag' => object['ETag'], + 'Date' => object['Date'] + } else raise Fog::Storage::HP::NotFound end diff --git a/tests/hp/requests/storage/container_tests.rb b/tests/hp/requests/storage/container_tests.rb index 940f4beed..5998e4d23 100644 --- a/tests/hp/requests/storage/container_tests.rb +++ b/tests/hp/requests/storage/container_tests.rb @@ -14,8 +14,8 @@ Shindo.tests("Fog::Storage[:hp] | container requests", ['hp']) do Fog::Storage[:hp].put_container('fogcontainertests') end - tests("#post_container('fogcontainertests', {'X-Container-Sync-Key' => 'keyd'})").succeeds do - Fog::Storage[:hp].post_container('fogcontainertests', {'X-Container-Meta-Foo' => 'd'}) + tests("#post_container('fogcontainertests', {'X-Container-Meta-Foo' => 'foometa'})").succeeds do + Fog::Storage[:hp].post_container('fogcontainertests', {'X-Container-Meta-Foo' => 'foometa'}) end tests("#get_container('fogcontainertests')").formats(@container_format) do diff --git a/tests/hp/requests/storage/object_tests.rb b/tests/hp/requests/storage/object_tests.rb index 1bd35d3e4..389854c7c 100644 --- a/tests/hp/requests/storage/object_tests.rb +++ b/tests/hp/requests/storage/object_tests.rb @@ -9,8 +9,8 @@ Shindo.tests("Fog::Storage[:hp] | object requests", ['hp', 'storage']) do Fog::Storage[:hp].put_object(@dir_name, 'fog_object', lorem_file) end - tests("#post_object('#{@dir_name}', 'fog_object', {})").succeeds do - Fog::Storage[:hp].post_object(@dir_name, 'fog_object', {}) + tests("#post_object('#{@dir_name}', 'fog_object', {'X-Object-Meta-Foo' => 'foometa'})").succeeds do + Fog::Storage[:hp].post_object(@dir_name, 'fog_object', {'X-Object-Meta-Foo' => 'foometa'}) end tests("#get_object('#{@dir_name}', 'fog_object')").succeeds do