1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

set status, headers and body before hitting after filters. fixes #402.

This commit is contained in:
Konstantin Haase 2012-01-04 00:33:35 +01:00
parent 6a91fa89b8
commit 301556abc3
3 changed files with 21 additions and 4 deletions

View file

@ -12,6 +12,9 @@
Moreover, it will be ignored if the value is not between 400 and 599. You
should use Exception#http_status instead. (Konstantin Haase)
* Status, headers and body will be set correctly in an after filter when using
halt in a before filter or route. (Konstantin Haase)
= 1.3.2 / 2011-12-30
* Don't automatically add `Rack::CommonLogger` if `Rack::Server` is adding it,

View file

@ -877,15 +877,18 @@ module Sinatra
elsif res.respond_to? :each
body res
end
nil # avoid double setting the same response tuple twice
end
# Dispatch a request with error handling.
def dispatch!
static! if settings.static? && (request.get? || request.head?)
filter! :before
route!
invoke do
static! if settings.static? && (request.get? || request.head?)
filter! :before
route!
end
rescue ::Exception => boom
handle_exception!(boom)
invoke { handle_exception!(boom) }
ensure
filter! :after unless env['sinatra.static_file']
end

View file

@ -531,6 +531,17 @@ class RoutingTest < Test::Unit::TestCase
assert_equal 'HelloWorldHowAreYou', body
end
it 'sets response.status with halt' do
status_was = nil
mock_app do
after { status_was = status }
get('/') { halt 500, 'error' }
end
get '/'
assert_status 500
assert_equal 500, status_was
end
it "transitions to the next matching route on pass" do
mock_app {
get '/:foo' do