lib/usher/interface/rack.rb in usher-0.7.5 vs lib/usher/interface/rack.rb in usher-0.8.0
- old
+ new
@@ -31,11 +31,11 @@
allow_identical_variable_names = options.key?(:allow_identical_variable_names) ? options[:allow_identical_variable_names] : false
self.redirect_on_trailing_delimiters = options.key?(:redirect_on_trailing_delimiters) ? options.delete(:redirect_on_trailing_delimiters) : false
if redirect_on_trailing_delimiters
options[:ignore_trailing_delimiters] = true
end
- usher_options = {:request_methods => request_methods, :generator => generator, :allow_identical_variable_names => allow_identical_variable_names}
+ usher_options = {:request_methods => request_methods, :generator => generator, :allow_identical_variable_names => allow_identical_variable_names, :detailed_failure => true}
usher_options.merge!(options)
@router = Usher.new(usher_options)
@router.route_class = Rack::Route
instance_eval(&blk) if blk
@@ -118,16 +118,16 @@
def call(env)
env[router_key] = self
request = ::Rack::Request.new(env)
response = @router.recognize(request, request.path_info)
- if redirect_on_trailing_delimiters and response.only_trailing_delimiters and (request.get? || request.head?)
+ if response.succeeded? && redirect_on_trailing_delimiters and response.only_trailing_delimiters and (request.get? || request.head?)
response = ::Rack::Response.new
response.redirect(request.path_info[0, request.path_info.size - 1], 302)
response.finish
else
- after_match(request, response) if response
+ after_match(request, response) if response.succeeded?
determine_respondant(response).call(env)
end
end
def generate(route, options = nil)
@@ -159,14 +159,18 @@
# If there is a matching route to an application, that
# application is called, Otherwise the middleware application is called.
#
# @api private
def determine_respondant(response)
- usable_response = use_destinations? && response && response.destination
+ usable_response = response.succeeded? && use_destinations? && response && response.destination
if usable_response && response.destination.respond_to?(:call)
response.destination
elsif usable_response && response.destination.respond_to?(:args) && response.destination.args.first.respond_to?(:call)
response.args.first
+ elsif !response.succeeded? && response.request_method?
+ rack_response = ::Rack::Response.new("Method not allowed", 405)
+ rack_response['Allow'] = response.acceptable_responses_only_strings.join(", ")
+ proc { |env| rack_response.finish }
else
_app
end
end