Skip to content

Commit

Permalink
Bring config.allow_concurrency back
Browse files Browse the repository at this point in the history
Since the Rack::Lock still exists in development,
let's provide a way to disable it explicitly.
  • Loading branch information
José Valim committed Mar 3, 2013
1 parent 86cf7a2 commit 9ee6f3c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 19 deletions.
58 changes: 40 additions & 18 deletions railties/lib/rails/application.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -305,22 +305,8 @@ def reload_dependencies? #:nodoc:
def default_middleware_stack #:nodoc: def default_middleware_stack #:nodoc:
ActionDispatch::MiddlewareStack.new.tap do |middleware| ActionDispatch::MiddlewareStack.new.tap do |middleware|
app = self 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" require "action_dispatch/http/rack_cache"
middleware.use ::Rack::Cache, rack_cache middleware.use ::Rack::Cache, rack_cache
end end
Expand All @@ -337,12 +323,14 @@ def default_middleware_stack #:nodoc:
middleware.use ::ActionDispatch::Static, paths["public"].first, config.static_cache_control middleware.use ::ActionDispatch::Static, paths["public"].first, config.static_cache_control
end end


middleware.use ::Rack::Lock unless config.cache_classes middleware.use ::Rack::Lock unless allow_concurrency?
middleware.use ::Rack::Runtime middleware.use ::Rack::Runtime
middleware.use ::Rack::MethodOverride middleware.use ::Rack::MethodOverride
middleware.use ::ActionDispatch::RequestId 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::DebugExceptions, app
middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies


Expand All @@ -368,6 +356,40 @@ def default_middleware_stack #:nodoc:
end end
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: def build_original_fullpath(env) #:nodoc:
path_info = env["PATH_INFO"] path_info = env["PATH_INFO"]
query_string = env["QUERY_STRING"] query_string = env["QUERY_STRING"]
Expand Down
3 changes: 2 additions & 1 deletion railties/lib/rails/application/configuration.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Rails module Rails
class Application class Application
class Configuration < ::Rails::Engine::Configuration 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, :cache_classes, :cache_store, :consider_all_requests_local, :console,
:eager_load, :exceptions_app, :file_watcher, :filter_parameters, :eager_load, :exceptions_app, :file_watcher, :filter_parameters,
:force_ssl, :helpers_paths, :logger, :log_formatter, :log_tags, :force_ssl, :helpers_paths, :logger, :log_formatter, :log_tags,
Expand All @@ -20,6 +20,7 @@ class Configuration < ::Rails::Engine::Configuration
def initialize(*) def initialize(*)
super super
self.encoding = "utf-8" self.encoding = "utf-8"
@allow_concurrency = nil
@consider_all_requests_local = false @consider_all_requests_local = false
@filter_parameters = [] @filter_parameters = []
@filter_redirect = [] @filter_redirect = []
Expand Down
6 changes: 6 additions & 0 deletions railties/test/application/middleware_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ def app
assert !middleware.include?("Rack::Lock") assert !middleware.include?("Rack::Lock")
end 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 test "removes static asset server if serve_static_assets is disabled" do
add_to_config "config.serve_static_assets = false" add_to_config "config.serve_static_assets = false"
boot! boot!
Expand Down

0 comments on commit 9ee6f3c

Please sign in to comment.