aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-02-09 08:50:28 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2014-02-09 08:50:28 -0800
commit33be58b2060b1e859e8da370b911822c20028690 (patch)
tree5cb9e699fb7721188c58853b93c7e27d11da58cb
parenta5ee843d9165fe6dbecb566f2315a8ca8c0c78ed (diff)
parent069bc273853c90194606b1725113d77ae39e2edd (diff)
downloadrails-33be58b2060b1e859e8da370b911822c20028690.tar.gz
rails-33be58b2060b1e859e8da370b911822c20028690.tar.bz2
rails-33be58b2060b1e859e8da370b911822c20028690.zip
Merge pull request #13982 from dskang/fix-response-flatten-infinite-recursion
Fix response flatten infinite recursion
-rw-r--r--actionpack/lib/action_dispatch/http/response.rb2
-rw-r--r--actionpack/test/dispatch/response_test.rb18
2 files changed, 19 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index bc13ee00f1..2c6bcf7b7b 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -313,7 +313,7 @@ module ActionDispatch # :nodoc:
header.delete CONTENT_TYPE
[status, header, []]
else
- [status, header, self]
+ [status, header, Rack::BodyProxy.new(self){}]
end
end
end
diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb
index 4501ea095c..959a3bc5cd 100644
--- a/actionpack/test/dispatch/response_test.rb
+++ b/actionpack/test/dispatch/response_test.rb
@@ -217,6 +217,24 @@ class ResponseTest < ActiveSupport::TestCase
assert_not @response.respond_to?(:method_missing)
assert @response.respond_to?(:method_missing, true)
end
+
+ test "can be destructured into status, headers and an enumerable body" do
+ response = ActionDispatch::Response.new(404, { 'Content-Type' => 'text/plain' }, ['Not Found'])
+ status, headers, body = response
+
+ assert_equal 404, status
+ assert_equal({ 'Content-Type' => 'text/plain' }, headers)
+ assert_equal ['Not Found'], body.each.to_a
+ end
+
+ test "[response].flatten does not recurse infinitely" do
+ Timeout.timeout(1) do # use a timeout to prevent it stalling indefinitely
+ status, headers, body = [@response].flatten
+ assert_equal @response.status, status
+ assert_equal @response.headers, headers
+ assert_equal @response.body, body.each.to_a.join
+ end
+ end
end
class ResponseIntegrationTest < ActionDispatch::IntegrationTest