seancribbs/webmachine-ruby — pull request #173 by Asmod4n (2014-07-02 16:35:54+00:00)
Title: Clarify changes made to Rack::RequestBody

While the Rack Spec doesn't need Servers to have a #to_io method for request bodies at the moment, Puma for instance does it currently: https://github.com/puma/puma/blob/v2.8.2/lib/puma/client.rb#L27.
Yahns, Unicorn and Rainbows don't even use standard ruby sockets but http://bogomips.org/kgio/ which are compatible but don't have a #to_io method for their request bodies.

To use this in a Webmachine::Resource
```ruby
class UploadResource < Webmachine::Resource
def allowed_methods; %W[POST]; end

def content_types_accepted
[['multipart/form-data', :from_form]]
end

def process_post
@request.body.to_io.each do |body|
puts body
end
true
end

def from_form; end
end
```

This has the advantage that you don't cache the whole body in memory like the current rack adapter does it with
@request.body.each.

Please be aware: only the rack adapter has this #to_io method currently guaranteed for request bodies, others don't have it necessarily.