diff --git a/lib/puma/request.rb b/lib/puma/request.rb index 94899289..c9f4c547 100644 --- a/lib/puma/request.rb +++ b/lib/puma/request.rb @@ -116,7 +116,11 @@ module Puma line_ending = LINE_END content_length = res_info[:content_length] - response_hijack = res_info[:response_hijack] + if res_body && !res_body.respond_to?(:each) + response_hijack = res_body + else + response_hijack = res_info[:response_hijack] + end if res_info[:no_body] if content_length and status != 204 diff --git a/test/test_puma_server.rb b/test/test_puma_server.rb index 1856a297..4909f268 100644 --- a/test/test_puma_server.rb +++ b/test/test_puma_server.rb @@ -116,6 +116,21 @@ class TestPumaServer < Minitest::Test assert_equal "[::1]\n80", data.split("\r\n").last end + def test_streaming_body + server_run do |env| + body = lambda do |stream| + stream.write("Hello World") + stream.close + end + + [200, {}, body] + end + + data = send_http_and_read "GET / HTTP/1.0\r\nConnection: close\r\n\r\n" + + assert_equal "Hello World", data.split("\n").last + end + def test_proper_stringio_body data = nil