Skip to content

Commit a3388f7

Browse files
committed
Slightly more consistent implementation of body=.
1 parent 2bc2263 commit a3388f7

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

actionpack/lib/action_dispatch/http/response.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,17 @@ def write(string)
355355

356356
# Allows you to manually set or override the response body.
357357
def body=(body)
358-
if body.is_a?(String)
359-
@stream = build_buffer(self, [body])
360-
elsif body.respond_to?(:to_path)
361-
@stream = body
362-
elsif body.respond_to?(:to_ary)
363-
synchronize do
358+
# Prevent ActionController::Metal::Live::Response from committing the response prematurely.
359+
synchronize do
360+
if body.respond_to?(:to_str)
361+
@stream = build_buffer(self, [body])
362+
elsif body.respond_to?(:to_path)
363+
@stream = body
364+
elsif body.respond_to?(:to_ary)
364365
@stream = build_buffer(self, body)
366+
else
367+
@stream = body
365368
end
366-
else
367-
@stream = body
368369
end
369370
end
370371

0 commit comments

Comments
 (0)