fog/fog — pull request #2165 by dgutov (2013-09-22 04:20:36+00:00)
Title: Fog::Storage::OpenStack::Real#put_object: Don't use data when block is provided

Without adding the WebMock-related lines, the `#put_object` test passes, but the `#get_object` after it fails, because the object gets created with empty body.

With WebMock properly disabled, I get `Excon::Errors::HTTPStatusError` wth status 499, because that's what Swift returns when [Content-Length header value is provided and doesn't match the request](http://blog.chmouel.com/2012/02/06/anatomy-of-a-swift-put-query-to-object-server/). The obvious fix is not to use the `data` argument at all when `block` is provided.

```
put_object with block
#put_object('fogobjecttests', 'fog_object', &block) - succeeds
Expected(201) <=> Actual(499 Unknown)
request => {:chunk_size=>1048576, :connect_timeout=>60, :debug_request=>true, :debug_response=>true, :headers=>{"User-Agent"=>"fog/1.15.0", "Content-Type"=>nil, "X-Auth-Token"=>"MIIE8gYJKoZIhvcNAQcCoIIE4zCCBN8CAQExCTAHBgUrDgMCGjCCA8sGCSqGSIb3DQEHAaCCA7wEggO4eyJhY2Nlc3MiOiB7InRva2VuIjogeyJpc3N1ZWRfYXQiOiAiMjAxMy0wOS0yMlQwMzo0NjowNS4yMjM4MjIiLCAiZXhwaXJlcyI6ICIyMDEzLTA5LTIzVDAzOjQ2OjA1WiIsICJpZCI6ICJwbGFjZWhvbGRlciIsICJ0ZW5hbnQiOiB7ImRlc2NyaXB0aW9uIjogIlRlbmFudCBmb3IgdXNpbmcgZnJvbSB0aGUgd2ViIHNlcnZpY2VzIiwgImVuYWJsZWQiOiB0cnVlLCAiaWQiOiAiMTY0YzY1NzMwN2YwNDIxMmI0MDgxMzZiODE2ZWY3NDMiLCAibmFtZSI6ICJyZXNlbGxlcl90ZW5hbnQifX0sICJzZXJ2aWNlQ2F0YWxvZyI6IFt7ImVuZHBvaW50cyI6IFt7ImFkbWluVVJMIjogImh0dHA6Ly8xOTIuMTY4LjMzLjEwOjgwODAvdjEiLCAicmVnaW9uIjogIkRldmVsb3AiLCAiaW50ZXJuYWxVUkwiOiAiaHR0cDovLzE5Mi4xNjguMzMuMT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"Content-Length"=>0, "Host"=>"192.168.33.10:8080", "Transfer-Encoding"=>"chunked"}, :idempotent=>false, :instrumentor_name=>"excon", :middlewares=>[Excon::Middleware::ResponseParser, Excon::Middleware::Expects, Excon::Middleware::Idempotent, Excon::Middleware::Instrumentor, Excon::Middleware::Mock], :mock=>nil, :nonblock=>true, :omit_default_port=>false, :read_timeout=>60, :retry_limit=>4, :ssl_verify_peer=>true, :tcp_nodelay=>false, :uri_parser=>URI, :write_timeout=>60, :host=>"192.168.33.10", :path=>"/v1/AUTH_164c657307f04212b408136b816ef743/fogobjecttests/fog_block_object", :port=>"8080", :query=>nil, :scheme=>"http", :user=>nil, :password=>nil, :__construction_args=>{:host=>"192.168.33.10", :path=>"", :port=>"8080", :query=>nil, :scheme=>"http", :user=>nil, :password=>nil, :debug_response=>true, :headers=>{"User-Agent"=>"fog/1.15.0"}}, :request_block=>#, :expects=>201, :method=>"PUT", :retries_remaining=>4}
response => #"

Client Disconnect

The client was disconnected during request.

", :headers=>{"Last-Modified"=>"Sun, 22 Sep 2013 03:46:05 GMT", "Content-Length"=>"89", "Content-Type"=>"text/html; charset=UTF-8", "Date"=>"Sun, 22 Sep 2013 03:46:06 GMT"}, :status=>499, :remote_ip=>"192.168.33.10"}, @body="

Client Disconnect

The client was disconnected during request.

", @headers={"Last-Modified"=>"Sun, 22 Sep 2013 03:46:05 GMT", "Content-Length"=>"89", "Content-Type"=>"text/html; charset=UTF-8", "Date"=>"Sun, 22 Sep 2013 03:46:06 GMT"}, @status=499, @remote_ip="192.168.33.10"> (Excon::Errors::HTTPStatusError)
/home/gutov/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/excon-0.25.3/lib/excon/middlewares/expects.rb:10:in `response_call'
/home/gutov/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/excon-0.25.3/lib/excon/middlewares/response_parser.rb:8:in `response_call'
/home/gutov/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/excon-0.25.3/lib/excon/connection.rb:350:in `response'
/home/gutov/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/excon-0.25.3/lib/excon/connection.rb:248:in `request'
/home/gutov/vc/fog/lib/fog/core/connection.rb:57:in `request'
/home/gutov/vc/fog/lib/fog/core/deprecated/connection.rb:20:in `request'
/home/gutov/vc/fog/lib/fog/openstack/storage.rb:145:in `request'
/home/gutov/vc/fog/lib/fog/openstack/requests/storage/put_object.rb:28:in `put_object'
/home/gutov/vc/fog/tests/openstack/requests/storage/object_tests.rb:53:in `block (4 levels) in '
tests/helpers/succeeds_helper.rb:6:in `instance_eval'
tests/helpers/succeeds_helper.rb:6:in `block in succeeds'
...
```

Notes:

* I haven't found a better place to put the WebMock workaround.
* The Rackspace code may need a similar fix.