Permalink
Browse files

fix 404 handling

  • Loading branch information...
1 parent a4ecbb1 commit a8f1cc52ef2af04f00df29133b036d4ef30114ea @dayflower dayflower committed Oct 31, 2012
@@ -914,14 +914,23 @@ def dispatch!
filter! :after unless env['sinatra.static_file']
end
+ ROUTE_NOT_FOUND_STATUS = 9404
+
def route!(base=settings, pass_block=nil)
Thread.current['padrino.instance'] = self
+ if base.compiled_router
+ base.compiled_router.default(proc{|env| ::Rack::Response.new('Route Not Found', ROUTE_NOT_FOUND_STATUS, {'X-Cascade' => 'pass'}).finish})
+ end
if base.compiled_router and match = base.compiled_router.call(@request.env)
if match.respond_to?(:each)
route_eval do
- match[1].each {|k,v| response[k] = v}
- status match[0]
- route_missing if match[0] == 404
+ if match[0] == ROUTE_NOT_FOUND_STATUS
+ status 404
+ route_missing
+ else
+ match[1].each {|k,v| response[k] = v}
+ status match[0]
+ end
end
end
else
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
# s.post_install_message << "\n\e[32m" + ("*" * 20) + "\n\e[0m"
s.add_dependency("tilt", "~> 1.3.0")
- s.add_dependency("sinatra", "= 1.3.2")
+ s.add_dependency("sinatra", "~> 1.3.1")
s.add_dependency("http_router", "~> 0.10.2")
s.add_dependency("thor", "~> 0.15.2")
s.add_dependency("activesupport", "~> 3.2.0")
@@ -1629,11 +1629,12 @@ def authorize(username, password)
should 'render a custom 404 page' do
mock_app do
- error(404) { "not found" }
+ error(404) { "custom 404 not found" }
end
get "/"
assert_equal 404, status
- assert_match /not found/, body
+ assert_equal "custom 404 not found", body
+ assert_equal "custom 404 not found".length.to_s, headers['Content-Length']
end
should 'recognize paths' do

0 comments on commit a8f1cc5

Please sign in to comment.