aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/http/request.rb19
-rw-r--r--actionpack/lib/action_dispatch/http/response.rb6
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb14
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb28
4 files changed, 45 insertions, 22 deletions
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb
index a3c6f015d9..e6387768de 100644
--- a/actionpack/lib/action_dispatch/http/request.rb
+++ b/actionpack/lib/action_dispatch/http/request.rb
@@ -68,16 +68,23 @@ module ActionDispatch
end
end
+ PASS_NOT_FOUND = Class.new { # :nodoc:
+ def self.action(_); self; end
+ def self.call(_); [404, {'X-Cascade' => 'pass'}, []]; end
+ }
+
def controller_class
check_path_parameters!
params = path_parameters
- controller_param = params[:controller].underscore if params.key?(:controller)
- params[:action] ||= 'index'
-
- yield unless controller_param
- const_name = "#{controller_param.camelize}Controller"
- ActiveSupport::Dependencies.constantize(const_name)
+ if params.key?(:controller)
+ controller_param = params[:controller].underscore
+ params[:action] ||= 'index'
+ const_name = "#{controller_param.camelize}Controller"
+ ActiveSupport::Dependencies.constantize(const_name)
+ else
+ PASS_NOT_FOUND
+ end
end
def key?(key)
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index fd92e89231..d860e00217 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -65,7 +65,7 @@ module ActionDispatch # :nodoc:
CONTENT_TYPE = "Content-Type".freeze
SET_COOKIE = "Set-Cookie".freeze
LOCATION = "Location".freeze
- NO_CONTENT_CODES = [204, 304]
+ NO_CONTENT_CODES = [100, 101, 102, 204, 205, 304]
cattr_accessor(:default_charset) { "utf-8" }
cattr_accessor(:default_headers)
@@ -265,9 +265,6 @@ module ActionDispatch # :nodoc:
end
# The location header we'll be responding with.
- def location
- headers[LOCATION]
- end
alias_method :redirect_url, :location
# Sets the location header we'll be responding with.
@@ -396,6 +393,7 @@ module ActionDispatch # :nodoc:
if NO_CONTENT_CODES.include?(@status)
header.delete CONTENT_TYPE
+ header.delete 'Content-Length'
[status, header, []]
else
[status, header, RackBody.new(self)]
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index c3a9422ceb..1acfb2bfe8 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -283,12 +283,16 @@ module ActionDispatch
end
def app(blocks)
- if to.respond_to?(:call)
- Constraints.new(to, blocks, Constraints::CALL)
- elsif blocks.any?
- Constraints.new(dispatcher(defaults.key?(:controller)), blocks, Constraints::SERVE)
+ if to.is_a?(Class) && to < ActionController::Metal
+ Routing::RouteSet::StaticDispatcher.new to
else
- dispatcher(defaults.key?(:controller))
+ if to.respond_to?(:call)
+ Constraints.new(to, blocks, Constraints::CALL)
+ elsif blocks.any?
+ Constraints.new(dispatcher(defaults.key?(:controller)), blocks, Constraints::SERVE)
+ else
+ dispatcher(defaults.key?(:controller))
+ end
end
end
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 4e29476117..e4b8d5993e 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -27,11 +27,10 @@ module ActionDispatch
def dispatcher?; true; end
def serve(req)
- params = req.path_parameters
- controller = req.controller_class do
- return [404, {'X-Cascade' => 'pass'}, []]
- end
- dispatch(controller, params[:action], req)
+ params = req.path_parameters
+ controller = controller req
+ res = controller.make_response! req
+ dispatch(controller, params[:action], req, res)
rescue NameError => e
if @raise_on_name_error
raise ActionController::RoutingError, e.message, e.backtrace
@@ -42,9 +41,24 @@ module ActionDispatch
private
- def dispatch(controller, action, req)
- controller.action(action).call(req.env)
+ def controller(req)
+ req.controller_class
+ end
+
+ def dispatch(controller, action, req, res)
+ controller.dispatch(action, req, res)
+ end
+ end
+
+ class StaticDispatcher < Dispatcher
+ def initialize(controller_class)
+ super(false)
+ @controller_class = controller_class
end
+
+ private
+
+ def controller(_); @controller_class; end
end
# A NamedRouteCollection instance is a collection of named routes, and also