Skip to content

Commit

Permalink
can only safely stream natively on ActionDispatch <= 3.2
Browse files Browse the repository at this point in the history
since 4.0 Response#stream is added and body is wrapped in a buffer 
(which does more than body.each)

resolves #210 (broken Rails streaming for Rails 4.x)
  • Loading branch information
kares committed Aug 3, 2017
1 parent 0e0ba6a commit 91007c7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main/ruby/jruby/rack/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,11 @@ def write_body(response)
body = @body.to_inputstream # so that we close the stream
body = Channels.newChannel(body) # closing the channel closes the stream
transfer_channel body, response.getOutputStream
elsif @body.respond_to?(:body_parts) && @body.body_parts.respond_to?(:to_channel) &&
! object_polluted_with_anyio?(@body.body_parts, :to_channel)
elsif @body.respond_to?(:body_parts) && ! @body.respond_to?(:stream)
&& ( body_parts = @body.body_parts ).respond_to?(:to_channel) &&
! object_polluted_with_anyio?(body_parts, :to_channel)
# ActionDispatch::Response "raw" body access in case it's a File
body = @body.body_parts.to_channel # so that we close the channel
body = body_parts.to_channel # so that we close the channel
transfer_channel body, response.getOutputStream
else
if dechunk?
Expand Down

0 comments on commit 91007c7

Please sign in to comment.