mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Deprecate AC configuration values which were moved to Rack.
This commit is contained in:
parent
a8c5d22c23
commit
0dece7929c
7 changed files with 41 additions and 17 deletions
|
@ -15,9 +15,6 @@ module ActionController
|
|||
cattr_accessor :session_options
|
||||
self.session_options = {}
|
||||
|
||||
cattr_accessor :allow_concurrency
|
||||
self.allow_concurrency = false
|
||||
|
||||
cattr_accessor :relative_url_root
|
||||
self.relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT']
|
||||
|
||||
|
@ -44,9 +41,6 @@ module ActionController
|
|||
|
||||
self.page_cache_directory = defined?(Rails.public_path) ? Rails.public_path : ""
|
||||
|
||||
cattr_accessor :consider_all_requests_local
|
||||
self.consider_all_requests_local = true
|
||||
|
||||
# Prepends all the URL-generating helpers from AssetHelper. This makes it possible to easily move javascripts, stylesheets,
|
||||
# and images to a dedicated asset server away from the main web server. Example:
|
||||
# ActionController::Base.asset_host = "http://assets.example.com"
|
||||
|
@ -74,6 +68,25 @@ module ActionController
|
|||
|
||||
module ClassMethods
|
||||
def consider_all_requests_local
|
||||
ActiveSupport::Deprecation.warn "ActionController::Base.consider_all_requests_local is deprecated, " <<
|
||||
"use Rails.application.config.consider_all_requests_local instead"
|
||||
Rails.application.config.consider_all_requests_local
|
||||
end
|
||||
|
||||
def consider_all_requests_local=(value)
|
||||
ActiveSupport::Deprecation.warn "ActionController::Base.consider_all_requests_local= is no longer effective. " <<
|
||||
"Please configure it on your application with config.consider_all_requests_local="
|
||||
end
|
||||
|
||||
def allow_concurrency
|
||||
ActiveSupport::Deprecation.warn "ActionController::Base.allow_concurrency is deprecated, " <<
|
||||
"use Rails.application.config.allow_concurrency instead"
|
||||
Rails.application.config.allow_concurrency
|
||||
end
|
||||
|
||||
def allow_concurrency=(value)
|
||||
ActiveSupport::Deprecation.warn "ActionController::Base.allow_concurrency= is no longer effective. " <<
|
||||
"Please configure it on your application with config.allow_concurrency="
|
||||
end
|
||||
|
||||
def rescue_action(env)
|
||||
|
@ -86,6 +99,9 @@ module ActionController
|
|||
end
|
||||
end
|
||||
|
||||
delegate :consider_all_requests_local, :consider_all_requests_local=,
|
||||
:allow_concurrency, :allow_concurrency=, :to => :"self.class"
|
||||
|
||||
def render_to_body(options)
|
||||
if options.is_a?(Hash) && options.key?(:template)
|
||||
options[:template].sub!(/^\//, '')
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
class Rails::InfoController < ActionController::Base
|
||||
def properties
|
||||
if consider_all_requests_local || local_request?
|
||||
if consider_all_requests_local? || local_request?
|
||||
render :inline => Rails::Info.to_html
|
||||
else
|
||||
render :text => '<p>For security purposes, this information is only available to local requests.</p>', :status => :forbidden
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def consider_all_requests_local?
|
||||
Rails.application.config.consider_all_requests_local
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ module Rails
|
|||
class Configuration < ::Rails::Engine::Configuration
|
||||
include ::Rails::Configuration::Deprecated
|
||||
|
||||
attr_accessor :cache_classes, :cache_store, :colorize_logging,
|
||||
attr_accessor :allow_concurrency, :cache_classes, :cache_store, :colorize_logging,
|
||||
:consider_all_requests_local, :dependency_loading,
|
||||
:filter_parameters, :log_level, :logger, :metals,
|
||||
:plugins, :preload_frameworks, :reload_engines, :reload_plugins,
|
||||
|
@ -13,11 +13,13 @@ module Rails
|
|||
|
||||
def initialize(*)
|
||||
super
|
||||
@allow_concurrency = false
|
||||
@colorize_logging = true
|
||||
@filter_parameters = []
|
||||
@dependency_loading = true
|
||||
@serve_static_assets = true
|
||||
@time_zone = "UTC"
|
||||
@consider_all_requests_local = true
|
||||
end
|
||||
|
||||
def paths
|
||||
|
@ -50,7 +52,7 @@ module Rails
|
|||
self.preload_frameworks = true
|
||||
self.cache_classes = true
|
||||
self.dependency_loading = false
|
||||
self.action_controller.allow_concurrency = true if respond_to?(:action_controller)
|
||||
self.allow_concurrency = true
|
||||
self
|
||||
end
|
||||
|
||||
|
|
|
@ -8,10 +8,10 @@ module Rails
|
|||
def middleware
|
||||
@@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::Lock', :if => lambda { !Rails.application.config.allow_concurrency })
|
||||
middleware.use('::Rack::Runtime')
|
||||
middleware.use('::Rails::Rack::Logger')
|
||||
middleware.use('::ActionDispatch::ShowExceptions', lambda { ActionController::Base.consider_all_requests_local })
|
||||
middleware.use('::ActionDispatch::ShowExceptions', lambda { Rails.application.config.consider_all_requests_local })
|
||||
middleware.use('::ActionDispatch::Callbacks', lambda { !Rails.application.config.cache_classes })
|
||||
middleware.use('::ActionDispatch::Cookies')
|
||||
middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options })
|
||||
|
|
|
@ -93,7 +93,7 @@ module ApplicationTests
|
|||
RUBY
|
||||
|
||||
require "#{app_path}/config/application"
|
||||
assert AppTemplate::Application.config.action_controller.allow_concurrency
|
||||
assert AppTemplate::Application.config.allow_concurrency
|
||||
end
|
||||
|
||||
test "the application can be marked as threadsafe when there are no frameworks" do
|
||||
|
|
|
@ -39,7 +39,7 @@ module ApplicationTests
|
|||
end
|
||||
|
||||
test "removes lock if allow concurrency is set" do
|
||||
add_to_config "config.action_controller.allow_concurrency = true"
|
||||
add_to_config "config.allow_concurrency = true"
|
||||
boot!
|
||||
assert !middleware.include?("Rack::Lock")
|
||||
end
|
||||
|
|
|
@ -17,23 +17,23 @@ class InfoControllerTest < ActionController::TestCase
|
|||
ActionController::Routing::Routes.draw do |map|
|
||||
match ':controller/:action'
|
||||
end
|
||||
@controller.stubs(:consider_all_requests_local => false, :local_request? => true)
|
||||
@controller.stubs(:consider_all_requests_local? => false, :local_request? => true)
|
||||
end
|
||||
|
||||
test "info controller does not allow remote requests" do
|
||||
@controller.stubs(:consider_all_requests_local => false, :local_request? => false)
|
||||
@controller.stubs(:consider_all_requests_local? => false, :local_request? => false)
|
||||
get :properties
|
||||
assert_response :forbidden
|
||||
end
|
||||
|
||||
test "info controller renders an error message when request was forbidden" do
|
||||
@controller.stubs(:consider_all_requests_local => false, :local_request? => false)
|
||||
@controller.stubs(:consider_all_requests_local? => false, :local_request? => false)
|
||||
get :properties
|
||||
assert_select 'p'
|
||||
end
|
||||
|
||||
test "info controller allows requests when all requests are considered local" do
|
||||
@controller.stubs(:consider_all_requests_local => true, :local_request? => false)
|
||||
@controller.stubs(:consider_all_requests_local? => true, :local_request? => false)
|
||||
get :properties
|
||||
assert_response :success
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue