提交 e3a4eb4b 编写于 作者: J José Valim

Close the response body on cascade pass, closes #3975.

上级 19bea9f1
......@@ -17,6 +17,8 @@ def call(env)
# 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
......
......@@ -3,8 +3,18 @@
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 @@ def call(env)
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 @@ def call(env)
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 @@ def call(env)
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册