mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Close the response body on cascade pass, closes #3975.
This commit is contained in:
parent
19bea9f1bd
commit
e3a4eb4b40
2 changed files with 24 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue