lib/fog/rackspace/requests/storage/put_object.rb in fog-maestrodev-1.19.0.20140212012611 vs lib/fog/rackspace/requests/storage/put_object.rb in fog-maestrodev-1.20.0.20140305101305

- old
+ new

@@ -1,8 +1,9 @@ module Fog module Storage class Rackspace + class Real # Create a new object # # When passed a block, it will make a chunked request, calling @@ -34,8 +35,46 @@ ) request(params) end end + + class Mock + HeaderOptions = %w{ + Content-Type Access-Control-Allow-Origin Origin Content-Disposition + Etag Content-Encoding + }.freeze + + def put_object(container, object, data, options = {}, &block) + c = mock_container! container + + if block_given? + data = "" + loop do + chunk = yield + break if chunk.empty? + data << chunk + end + end + + o = c.add_object object, data + options.keys.each do |k| + o.meta[k] = options[k].to_s if k =~ /^X-Object-Meta/ + o.meta[k] = options[k] if HeaderOptions.include? k + end + + # Validate the provided Etag + etag = o.meta['Etag'] + if etag && etag != o.hash + c.remove_object object + raise Fog::Storage::Rackspace::ServiceError.new + end + + response = Excon::Response.new + response.status = 201 + response + end + end + end end end