Skip to content

Commit 49a3673

Browse files
committed
can only safely stream natively on ActionDispatch <= 3.2
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)
1 parent 0e0ba6a commit 49a3673

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/main/ruby/jruby/rack/response.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,11 @@ def write_body(response)
161161
body = @body.to_inputstream # so that we close the stream
162162
body = Channels.newChannel(body) # closing the channel closes the stream
163163
transfer_channel body, response.getOutputStream
164-
elsif @body.respond_to?(:body_parts) && @body.body_parts.respond_to?(:to_channel) &&
165-
! object_polluted_with_anyio?(@body.body_parts, :to_channel)
164+
elsif @body.respond_to?(:body_parts) && ! @body.respond_to?(:stream) &&
165+
( body_parts = @body.body_parts ).respond_to?(:to_channel) &&
166+
! object_polluted_with_anyio?(body_parts, :to_channel)
166167
# ActionDispatch::Response "raw" body access in case it's a File
167-
body = @body.body_parts.to_channel # so that we close the channel
168+
body = body_parts.to_channel # so that we close the channel
168169
transfer_channel body, response.getOutputStream
169170
else
170171
if dechunk?

0 commit comments

Comments
 (0)