aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@plataformatec.com.br>2013-03-03 13:20:44 -0700
committerJosé Valim <jose.valim@plataformatec.com.br>2013-03-03 13:20:44 -0700
commit9ee6f3cc8ef1cd50648ec2882803943d3bd1f24a (patch)
tree6060894be73e4d699528cc4b8acd8ef4b06e2c1e /railties
parent86cf7a2d166430fac1611aa7593b52b46eeb9f70 (diff)
downloadrails-9ee6f3cc8ef1cd50648ec2882803943d3bd1f24a.tar.gz
rails-9ee6f3cc8ef1cd50648ec2882803943d3bd1f24a.tar.bz2
rails-9ee6f3cc8ef1cd50648ec2882803943d3bd1f24a.zip
Bring config.allow_concurrency back
Since the Rack::Lock still exists in development, let's provide a way to disable it explicitly.
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/application.rb58
-rw-r--r--railties/lib/rails/application/configuration.rb3
-rw-r--r--railties/test/application/middleware_test.rb6
3 files changed, 48 insertions, 19 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index 5af7de720c..25cc36ff5d 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -305,22 +305,8 @@ module Rails
def default_middleware_stack #:nodoc:
ActionDispatch::MiddlewareStack.new.tap do |middleware|
app = self
- if rack_cache = config.action_dispatch.rack_cache
- begin
- require 'rack/cache'
- rescue LoadError => error
- error.message << ' Be sure to add rack-cache to your Gemfile'
- raise
- end
-
- if rack_cache == true
- rack_cache = {
- metastore: "rails:/",
- entitystore: "rails:/",
- verbose: false
- }
- end
+ if rack_cache = load_rack_cache
require "action_dispatch/http/rack_cache"
middleware.use ::Rack::Cache, rack_cache
end
@@ -337,12 +323,14 @@ module Rails
middleware.use ::ActionDispatch::Static, paths["public"].first, config.static_cache_control
end
- middleware.use ::Rack::Lock unless config.cache_classes
+ middleware.use ::Rack::Lock unless allow_concurrency?
middleware.use ::Rack::Runtime
middleware.use ::Rack::MethodOverride
middleware.use ::ActionDispatch::RequestId
- middleware.use ::Rails::Rack::Logger, config.log_tags # must come after Rack::MethodOverride to properly log overridden methods
- middleware.use ::ActionDispatch::ShowExceptions, config.exceptions_app || ActionDispatch::PublicExceptions.new(Rails.public_path)
+
+ # Must come after Rack::MethodOverride to properly log overridden methods
+ middleware.use ::Rails::Rack::Logger, config.log_tags
+ middleware.use ::ActionDispatch::ShowExceptions, show_exceptions_app
middleware.use ::ActionDispatch::DebugExceptions, app
middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies
@@ -368,6 +356,40 @@ module Rails
end
end
+ def allow_concurrency?
+ if config.allow_concurrency.nil?
+ config.cache_classes
+ else
+ config.allow_concurrency
+ end
+ end
+
+ def load_rack_cache
+ rack_cache = config.action_dispatch.rack_cache
+ return unless rack_cache
+
+ begin
+ require 'rack/cache'
+ rescue LoadError => error
+ error.message << ' Be sure to add rack-cache to your Gemfile'
+ raise
+ end
+
+ if rack_cache == true
+ {
+ metastore: "rails:/",
+ entitystore: "rails:/",
+ verbose: false
+ }
+ else
+ rack_cache
+ end
+ end
+
+ def show_exceptions_app
+ config.exceptions_app || ActionDispatch::PublicExceptions.new(Rails.public_path)
+ end
+
def build_original_fullpath(env) #:nodoc:
path_info = env["PATH_INFO"]
query_string = env["QUERY_STRING"]
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index 8abd2dc572..31fc80e544 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -5,7 +5,7 @@ require 'rails/engine/configuration'
module Rails
class Application
class Configuration < ::Rails::Engine::Configuration
- attr_accessor :asset_host, :assets, :autoflush_log,
+ attr_accessor :allow_concurrency, :asset_host, :assets, :autoflush_log,
:cache_classes, :cache_store, :consider_all_requests_local, :console,
:eager_load, :exceptions_app, :file_watcher, :filter_parameters,
:force_ssl, :helpers_paths, :logger, :log_formatter, :log_tags,
@@ -20,6 +20,7 @@ module Rails
def initialize(*)
super
self.encoding = "utf-8"
+ @allow_concurrency = nil
@consider_all_requests_local = false
@filter_parameters = []
@filter_redirect = []
diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb
index 73ef2046c0..d8076c7151 100644
--- a/railties/test/application/middleware_test.rb
+++ b/railties/test/application/middleware_test.rb
@@ -96,6 +96,12 @@ module ApplicationTests
assert !middleware.include?("Rack::Lock")
end
+ test "removes lock if allow concurrency is set" do
+ add_to_config "config.allow_concurrency = true"
+ boot!
+ assert !middleware.include?("Rack::Lock")
+ end
+
test "removes static asset server if serve_static_assets is disabled" do
add_to_config "config.serve_static_assets = false"
boot!