mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Cleanup dispatch path
This commit is contained in:
@@ -65,18 +65,23 @@ module ActionController
|
||||
include ActiveSupport::Callbacks
|
||||
define_callbacks :prepare_dispatch, :before_dispatch, :after_dispatch
|
||||
|
||||
# DEPRECATE: Remove arguments
|
||||
# DEPRECATE: Remove arguments, since they are only used by CGI
|
||||
def initialize(output = $stdout, request = nil, response = nil)
|
||||
@output, @request, @response = output, request, response
|
||||
@output = output
|
||||
@app = @@middleware.build(lambda { |env| self.dup._call(env) })
|
||||
end
|
||||
|
||||
def dispatch
|
||||
begin
|
||||
run_callbacks :before_dispatch
|
||||
handle_request
|
||||
controller = Routing::Routes.recognize(@request)
|
||||
controller.process(@request, @response).to_a
|
||||
rescue Exception => exception
|
||||
failsafe_rescue exception
|
||||
if controller ||= (::ApplicationController rescue Base)
|
||||
controller.process_with_exception(@request, @response, exception).to_a
|
||||
else
|
||||
raise exception
|
||||
end
|
||||
ensure
|
||||
run_callbacks :after_dispatch, :enumerator => :reverse_each
|
||||
end
|
||||
@@ -123,19 +128,5 @@ module ActionController
|
||||
return if @request.key?("rack.test")
|
||||
ActiveRecord::Base.clear_active_connections!
|
||||
end
|
||||
|
||||
protected
|
||||
def handle_request
|
||||
@controller = Routing::Routes.recognize(@request)
|
||||
@controller.process(@request, @response).out
|
||||
end
|
||||
|
||||
def failsafe_rescue(exception)
|
||||
if @controller ||= (::ApplicationController rescue Base)
|
||||
@controller.process_with_exception(@request, @response, exception).out
|
||||
else
|
||||
raise exception
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -83,7 +83,7 @@ module ActionController #:nodoc:
|
||||
@status || super
|
||||
end
|
||||
|
||||
def out(&block)
|
||||
def to_a(&block)
|
||||
@block = block
|
||||
@status = headers.delete("Status")
|
||||
if [204, 304].include?(status.to_i)
|
||||
@@ -93,7 +93,6 @@ module ActionController #:nodoc:
|
||||
[status, headers.to_hash, self]
|
||||
end
|
||||
end
|
||||
alias to_a out
|
||||
|
||||
def each(&callback)
|
||||
if @body.respond_to?(:call)
|
||||
|
||||
@@ -96,7 +96,9 @@ class DispatcherTest < Test::Unit::TestCase
|
||||
|
||||
private
|
||||
def dispatch(cache_classes = true)
|
||||
Dispatcher.any_instance.stubs(:handle_request).returns([200, {}, 'response'])
|
||||
controller = mock()
|
||||
controller.stubs(:process).returns([200, {}, 'response'])
|
||||
ActionController::Routing::Routes.stubs(:recognize).returns(controller)
|
||||
Dispatcher.define_dispatcher_callbacks(cache_classes)
|
||||
@dispatcher.call({})
|
||||
end
|
||||
|
||||
@@ -236,7 +236,7 @@ class RackResponseTest < BaseRackTest
|
||||
@response.body = "Hello, World!"
|
||||
@response.prepare!
|
||||
|
||||
status, headers, body = @response.out
|
||||
status, headers, body = @response.to_a
|
||||
assert_equal "200 OK", status
|
||||
assert_equal({
|
||||
"Content-Type" => "text/html; charset=utf-8",
|
||||
@@ -257,7 +257,7 @@ class RackResponseTest < BaseRackTest
|
||||
end
|
||||
@response.prepare!
|
||||
|
||||
status, headers, body = @response.out
|
||||
status, headers, body = @response.to_a
|
||||
assert_equal "200 OK", status
|
||||
assert_equal({"Content-Type" => "text/html; charset=utf-8", "Cache-Control" => "no-cache", "Set-Cookie" => []}, headers)
|
||||
|
||||
@@ -293,6 +293,6 @@ class RackResponseHeadersTest < BaseRackTest
|
||||
private
|
||||
def response_headers
|
||||
@response.prepare!
|
||||
@response.out[1]
|
||||
@response.to_a[1]
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user