Set X-Cascade header when using pass
Setting X-Cascade: pass allows middleware outside the Sinatra stack to continue trying to match the request. Signed-off-by: Ryan Tomayko <rtomayko@gmail.com>
This commit is contained in:
parent
3ef8eedef2
commit
f9a792396c
|
@ -585,6 +585,7 @@ module Sinatra
|
||||||
def handle_not_found!(boom)
|
def handle_not_found!(boom)
|
||||||
@env['sinatra.error'] = boom
|
@env['sinatra.error'] = boom
|
||||||
@response.status = 404
|
@response.status = 404
|
||||||
|
@response.headers['X-Cascade'] = 'pass'
|
||||||
@response.body = ['<h1>Not Found</h1>']
|
@response.body = ['<h1>Not Found</h1>']
|
||||||
error_block! boom.class, NotFound
|
error_block! boom.class, NotFound
|
||||||
end
|
end
|
||||||
|
|
|
@ -142,6 +142,19 @@ class HelpersTest < Test::Unit::TestCase
|
||||||
assert_equal 404, status
|
assert_equal 404, status
|
||||||
assert_equal '', body
|
assert_equal '', body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does not set a X-Cascade header' do
|
||||||
|
mock_app {
|
||||||
|
get '/' do
|
||||||
|
not_found
|
||||||
|
fail 'not_found should halt'
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
get '/'
|
||||||
|
assert_equal 404, status
|
||||||
|
assert_equal nil, response.headers['X-Cascade']
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'headers' do
|
describe 'headers' do
|
||||||
|
|
|
@ -60,6 +60,15 @@ class RoutingTest < Test::Unit::TestCase
|
||||||
assert_equal 404, status
|
assert_equal 404, status
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "404s and sets X-Cascade header when no route satisfies the request" do
|
||||||
|
mock_app {
|
||||||
|
get('/foo') { }
|
||||||
|
}
|
||||||
|
get '/bar'
|
||||||
|
assert_equal 404, status
|
||||||
|
assert_equal 'pass', response.headers['X-Cascade']
|
||||||
|
end
|
||||||
|
|
||||||
it "overrides the content-type in error handlers" do
|
it "overrides the content-type in error handlers" do
|
||||||
mock_app {
|
mock_app {
|
||||||
before { content_type 'text/plain' }
|
before { content_type 'text/plain' }
|
||||||
|
@ -462,6 +471,23 @@ class RoutingTest < Test::Unit::TestCase
|
||||||
assert not_found?
|
assert not_found?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "transitions to 404 and sets X-Cascade header when passed and no subsequent route matches" do
|
||||||
|
mock_app {
|
||||||
|
get '/:foo' do
|
||||||
|
pass
|
||||||
|
'Hello Foo'
|
||||||
|
end
|
||||||
|
|
||||||
|
get '/bar' do
|
||||||
|
'Hello Bar'
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
get '/foo'
|
||||||
|
assert not_found?
|
||||||
|
assert_equal 'pass', response.headers['X-Cascade']
|
||||||
|
end
|
||||||
|
|
||||||
it "uses optional block passed to pass as route block if no other route is found" do
|
it "uses optional block passed to pass as route block if no other route is found" do
|
||||||
mock_app {
|
mock_app {
|
||||||
get "/" do
|
get "/" do
|
||||||
|
|
Loading…
Reference in New Issue