diff options
author | Colin Curtin <colin@procore.com> | 2008-12-20 20:21:20 -0800 |
---|---|---|
committer | Colin Curtin <colin@procore.com> | 2008-12-20 20:21:20 -0800 |
commit | 0e121f9ed93ebb417cc63307aaaf47f8adfd220d (patch) | |
tree | 39530f289b38a5dd1b2e6b170dab2631c983aaf3 /actionpack/lib/action_controller/dispatcher.rb | |
parent | b0187434bd7601a5b2e5f7afac99c964e566b9db (diff) | |
parent | a0d091a41604d709cf2b99c85dcf4ae3ee275b9c (diff) | |
download | rails-0e121f9ed93ebb417cc63307aaaf47f8adfd220d.tar.gz rails-0e121f9ed93ebb417cc63307aaaf47f8adfd220d.tar.bz2 rails-0e121f9ed93ebb417cc63307aaaf47f8adfd220d.zip |
Merge branch 'master' of git@github.com:lifo/docrails
Diffstat (limited to 'actionpack/lib/action_controller/dispatcher.rb')
-rw-r--r-- | actionpack/lib/action_controller/dispatcher.rb | 59 |
1 files changed, 26 insertions, 33 deletions
diff --git a/actionpack/lib/action_controller/dispatcher.rb b/actionpack/lib/action_controller/dispatcher.rb index c9a9264b6d..11c4f057d8 100644 --- a/actionpack/lib/action_controller/dispatcher.rb +++ b/actionpack/lib/action_controller/dispatcher.rb @@ -2,8 +2,6 @@ module ActionController # Dispatches requests to the appropriate controller and takes care of # reloading the app after each request when Dependencies.load? is true. class Dispatcher - @@guard = Mutex.new - class << self def define_dispatcher_callbacks(cache_classes) unless cache_classes @@ -46,40 +44,49 @@ module ActionController cattr_accessor :middleware self.middleware = MiddlewareStack.new do |middleware| + middleware.use "ActionController::Lock", :if => lambda { + !ActionController::Base.allow_concurrency + } middleware.use "ActionController::Failsafe" - middleware.use "ActionController::SessionManagement::Middleware" + + ["ActionController::Session::CookieStore", + "ActionController::Session::MemCacheStore", + "ActiveRecord::SessionStore"].each do |store| + middleware.use(store, ActionController::Base.session_options, + :if => lambda { + if session_store = ActionController::Base.session_store + session_store.name == store + end + } + ) + end end 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_unlocked + 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 end - def dispatch - if ActionController::Base.allow_concurrency - dispatch_unlocked - else - @@guard.synchronize do - dispatch_unlocked - end - end - end - # DEPRECATE: Remove CGI support def dispatch_cgi(cgi, session_options) CGIHandler.dispatch_cgi(self, cgi, @output) @@ -118,22 +125,8 @@ module ActionController def checkin_connections # Don't return connection (and peform implicit rollback) if this request is a part of integration test # TODO: This callback should have direct access to env - return if @request.key?("action_controller.test") + 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 |