diff options
author | José Valim <jose.valim@gmail.com> | 2011-12-14 17:03:35 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-12-14 17:03:35 +0100 |
commit | e3a4eb4b4067ee7d906babd029e60565001f7808 (patch) | |
tree | 0a6777c56be3173130d92c5500ee34852685cba4 | |
parent | 19bea9f1bd03b4601bf4c38539bff993d3eebc39 (diff) | |
download | rails-e3a4eb4b4067ee7d906babd029e60565001f7808.tar.gz rails-e3a4eb4b4067ee7d906babd029e60565001f7808.tar.bz2 rails-e3a4eb4b4067ee7d906babd029e60565001f7808.zip |
Close the response body on cascade pass, closes #3975.
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/debug_exceptions.rb | 2 | ||||
-rw-r--r-- | actionpack/test/dispatch/debug_exceptions_test.rb | 25 |
2 files changed, 24 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb index cd4af82c6e..3904183823 100644 --- a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb @@ -17,6 +17,8 @@ module ActionDispatch # TODO: Maybe this should be in the router itself if response[1]['X-Cascade'] == 'pass' + body = response[2] + body.close if body.respond_to?(:close) raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}" end rescue Exception => exception diff --git a/actionpack/test/dispatch/debug_exceptions_test.rb b/actionpack/test/dispatch/debug_exceptions_test.rb index 6133bfe338..29fc248acc 100644 --- a/actionpack/test/dispatch/debug_exceptions_test.rb +++ b/actionpack/test/dispatch/debug_exceptions_test.rb @@ -3,8 +3,18 @@ require 'abstract_unit' class DebugExceptionsTest < ActionDispatch::IntegrationTest class Boomer + attr_accessor :closed + def initialize(detailed = false) @detailed = detailed + @closed = false + end + + def each + end + + def close + @closed = true end def call(env) @@ -12,7 +22,7 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest req = ActionDispatch::Request.new(env) case req.path when "/pass" - [404, { "X-Cascade" => "pass" }, []] + [404, { "X-Cascade" => "pass" }, self] when "/not_found" raise ActionController::UnknownAction when "/runtime_error" @@ -31,8 +41,8 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest end end - ProductionApp = ActionDispatch::DebugExceptions.new((Boomer.new(false))) - DevelopmentApp = ActionDispatch::DebugExceptions.new((Boomer.new(true))) + ProductionApp = ActionDispatch::DebugExceptions.new(Boomer.new(false)) + DevelopmentApp = ActionDispatch::DebugExceptions.new(Boomer.new(true)) test 'skip diagnosis if not showing detailed exceptions' do @app = ProductionApp @@ -55,6 +65,15 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest end end + test 'closes the response body on cascade pass' do + boomer = Boomer.new(false) + @app = ActionDispatch::DebugExceptions.new(boomer) + assert_raise ActionController::RoutingError do + get "/pass", {}, {'action_dispatch.show_exceptions' => true} + end + assert boomer.closed, "Expected to close the response body" + end + test "rescue with diagnostics message" do @app = DevelopmentApp |