aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-05-29 22:29:14 +0200
committerJosé Valim <jose.valim@gmail.com>2010-05-29 22:29:46 +0200
commit19d8c8cbe4aae570e3b48080e3182e5634aa7aec (patch)
tree4916366ccf706c49f7e2082a406a2a90471dff79 /railties/lib
parentd7f6f2b596d00a7deb4f83592aaa78436c5c3163 (diff)
downloadrails-19d8c8cbe4aae570e3b48080e3182e5634aa7aec.tar.gz
rails-19d8c8cbe4aae570e3b48080e3182e5634aa7aec.tar.bz2
rails-19d8c8cbe4aae570e3b48080e3182e5634aa7aec.zip
Remove the laziness from the middleware stack.
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails/application.rb28
-rw-r--r--railties/lib/rails/application/bootstrap.rb2
-rw-r--r--railties/lib/rails/application/configuration.rb28
-rw-r--r--railties/lib/rails/tasks/middleware.rake2
4 files changed, 31 insertions, 29 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index c588a41443..7416e94eeb 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -124,7 +124,10 @@ module Rails
end
def app
- @app ||= config.middleware.build(routes)
+ @app ||= begin
+ config.middleware = config.middleware.merge_into(default_middleware_stack)
+ config.middleware.build(routes)
+ end
end
def call(env)
@@ -148,6 +151,29 @@ module Rails
protected
+ def default_middleware_stack
+ ActionDispatch::MiddlewareStack.new.tap do |middleware|
+ middleware.use ::ActionDispatch::Static, paths.public.to_a.first if config.serve_static_assets
+ middleware.use ::Rack::Lock if !config.allow_concurrency
+ middleware.use ::Rack::Runtime
+ middleware.use ::Rails::Rack::Logger
+ middleware.use ::ActionDispatch::ShowExceptions, config.consider_all_requests_local if config.action_dispatch.show_exceptions
+ middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies
+ middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header
+ middleware.use ::ActionDispatch::Callbacks, !config.cache_classes
+ middleware.use ::ActionDispatch::Cookies
+
+ if config.session_store
+ middleware.use config.session_store, config.session_options
+ middleware.use ::ActionDispatch::Flash
+ end
+
+ middleware.use ::ActionDispatch::ParamsParser
+ middleware.use ::Rack::MethodOverride
+ middleware.use ::ActionDispatch::Head
+ end
+ end
+
def initialize_tasks
require "rails/tasks"
task :environment do
diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb
index e62eed8a87..0a435f0f36 100644
--- a/railties/lib/rails/application/bootstrap.rb
+++ b/railties/lib/rails/application/bootstrap.rb
@@ -47,7 +47,7 @@ module Rails
silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(config.cache_store) }
if RAILS_CACHE.respond_to?(:middleware)
- config.middleware.insert_after(:"Rack::Lock", RAILS_CACHE.middleware)
+ config.middleware.insert_before("Rack::Runtime", RAILS_CACHE.middleware)
end
end
end
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index f3a326f36d..25e54e9dce 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -9,7 +9,7 @@ module Rails
attr_accessor :allow_concurrency, :cache_classes, :cache_store,
:encoding, :consider_all_requests_local, :dependency_loading,
- :filter_parameters, :log_level, :logger,
+ :filter_parameters, :log_level, :logger, :middleware,
:plugins, :preload_frameworks, :reload_engines, :reload_plugins,
:secret_token, :serve_static_assets, :session_options,
:time_zone, :whiny_nils
@@ -25,6 +25,7 @@ module Rails
@session_store = :cookie_store
@session_options = {}
@time_zone = "UTC"
+ @middleware = app_middleware
end
def encoding=(value)
@@ -41,10 +42,6 @@ module Rails
end
end
- def middleware
- @middleware ||= app_middleware.merge_into(default_middleware_stack)
- end
-
def paths
@paths ||= begin
paths = super
@@ -134,27 +131,6 @@ module Rails
@session_options = args.shift || {}
end
end
-
- protected
-
- def default_middleware_stack
- ActionDispatch::MiddlewareStack.new.tap do |middleware|
- middleware.use('::ActionDispatch::Static', lambda { paths.public.to_a.first }, :if => lambda { serve_static_assets })
- middleware.use('::Rack::Lock', :if => lambda { !allow_concurrency })
- middleware.use('::Rack::Runtime')
- middleware.use('::Rails::Rack::Logger')
- middleware.use('::ActionDispatch::ShowExceptions', lambda { consider_all_requests_local }, :if => lambda { action_dispatch.show_exceptions })
- middleware.use('::ActionDispatch::RemoteIp', lambda { action_dispatch.ip_spoofing_check }, lambda { action_dispatch.trusted_proxies })
- middleware.use('::Rack::Sendfile', lambda { action_dispatch.x_sendfile_header })
- middleware.use('::ActionDispatch::Callbacks', lambda { !cache_classes })
- middleware.use('::ActionDispatch::Cookies')
- middleware.use(lambda { session_store }, lambda { session_options })
- middleware.use('::ActionDispatch::Flash', :if => lambda { session_store })
- middleware.use('::ActionDispatch::ParamsParser')
- middleware.use('::Rack::MethodOverride')
- middleware.use('::ActionDispatch::Head')
- end
- end
end
end
end
diff --git a/railties/lib/rails/tasks/middleware.rake b/railties/lib/rails/tasks/middleware.rake
index 251da67c96..e670989345 100644
--- a/railties/lib/rails/tasks/middleware.rake
+++ b/railties/lib/rails/tasks/middleware.rake
@@ -1,6 +1,6 @@
desc 'Prints out your Rack middleware stack'
task :middleware => :environment do
- Rails.configuration.middleware.active.each do |middleware|
+ Rails.configuration.middleware.each do |middleware|
puts "use #{middleware.inspect}"
end
puts "run #{Rails::Application.instance.class.name}.routes"