Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 301556abc3a4380554c63b32c9c6161e95e07970 1 parent 6a91fa8
@rkh rkh authored
Showing with 21 additions and 4 deletions.
  1. +3 −0  CHANGES
  2. +7 −4 lib/sinatra/base.rb
  3. +11 −0 test/routing_test.rb
View
3  CHANGES
@@ -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
11 lib/sinatra/base.rb
@@ -877,15 +877,18 @@ def invoke
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
11 test/routing_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.