Permalink
Browse files

Default middleware stack needs to be available at configuration time

  • Loading branch information...
1 parent 56b28ec commit 76b5f18feba3f1d0507b4c4ec34d11d9bb1c493c @josh josh committed Jan 5, 2010
@@ -23,26 +23,6 @@ class Railtie < Rails::Railtie
app.reload_routes!
end
- # Include middleware to serve up static assets
- initializer "action_controller.initialize_static_server" do |app|
- if app.config.serve_static_assets
- app.config.middleware.use(ActionDispatch::Static, Rails.public_path)
- end
- end
-
- initializer "action_controller.initialize_middleware_stack" do |app|
- middleware = app.config.middleware
- middleware.use(::Rack::Lock, :if => lambda { ActionController::Base.allow_concurrency })
- middleware.use(::Rack::Runtime)
- middleware.use(ActionDispatch::ShowExceptions, lambda { ActionController::Base.consider_all_requests_local })
- middleware.use(ActionDispatch::Callbacks, lambda { ActionController::Dispatcher.prepare_each_request })
- middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options })
- middleware.use(ActionDispatch::ParamsParser)
- middleware.use(::Rack::MethodOverride)
- middleware.use(::Rack::Head)
- middleware.use(ActionDispatch::StringCoercion)
- end
-
initializer "action_controller.initialize_framework_caches" do
ActionController::Base.cache_store ||= RAILS_CACHE
end
@@ -4,11 +4,25 @@ module Rails
# Temporarily separate the plugin configuration class from the main
# configuration class while this bit is being cleaned up.
class Railtie::Configuration
-
def self.default
@default ||= new
end
+ def self.default_middleware_stack
+ ActionDispatch::MiddlewareStack.new.tap do |middleware|
+ middleware.use('ActionDispatch::Static', lambda { Rails.public_path }, :if => lambda { Rails.application.config.serve_static_assets })
+ middleware.use('::Rack::Lock', :if => lambda { !ActionController::Base.allow_concurrency })
+ middleware.use('::Rack::Runtime')
+ middleware.use('ActionDispatch::ShowExceptions', lambda { ActionController::Base.consider_all_requests_local })
+ middleware.use('ActionDispatch::Callbacks', lambda { ActionController::Dispatcher.prepare_each_request })
+ middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options })
+ middleware.use('ActionDispatch::ParamsParser')
+ middleware.use('::Rack::MethodOverride')
+ middleware.use('::Rack::Head')
+ middleware.use('ActionDispatch::StringCoercion')
+ end
+ end
+
attr_reader :middleware
def initialize(base = nil)
@@ -17,7 +31,7 @@ def initialize(base = nil)
@middleware = base.middleware.dup
else
@options = Hash.new { |h,k| h[k] = ActiveSupport::OrderedOptions.new }
- @middleware = ActionDispatch::MiddlewareStack.new
+ @middleware = self.class.default_middleware_stack
end
end
@@ -230,7 +244,7 @@ def log_path
def log_level
@log_level ||= RAILS_ENV == 'production' ? :info : :debug
end
-
+
def time_zone
@time_zone ||= "UTC"
end
@@ -55,6 +55,18 @@ def setup
assert_equal "Rack::Config", middleware.last
end
+ test "insert middleware after" do
+ add_to_config "config.middleware.insert_after ActionDispatch::Static, Rack::Config"
+ boot!
+ assert_equal "Rack::Config", middleware.second
+ end
+
+ test "insert middleware before" do
+ add_to_config "config.middleware.insert_before ActionDispatch::Static, Rack::Config"
+ boot!
+ assert_equal "Rack::Config", middleware.first
+ end
+
private
def boot!
require "#{app_path}/config/environment"

0 comments on commit 76b5f18

Please sign in to comment.