Can I have Sinatra / Rack not read the entire request body into memory?

Posted by Chris Markle on Stack Overflow See other posts from Stack Overflow or by Chris Markle
Published on 2010-06-12T05:08:20Z Indexed on 2010/06/12 17:32 UTC
Read the original article Hit count: 153

Filed under:
|
|

Say I have a Sinatra route ala:

put '/data' do
  request.body.read
  # ...
end

It appears that the entire request.body is read into memory. Is there a way to consume the body as it comes into the system, rather than having it all buffered in Rack/Sinatra beforehand?

I see I can do this to read the body in parts, but the entire body still seems to be read into memory beforehand.

put '/data' do
  while request.body.read(1024) != nil 
    # ...
  end
  # ...
end

© Stack Overflow or respective owner

Related posts about sinatra

Related posts about httprequest