2009-04-27 21:21:26 -04:00
|
|
|
module ActionController
|
2009-12-02 23:01:01 -05:00
|
|
|
module Compatibility
|
2009-05-28 12:35:36 -04:00
|
|
|
extend ActiveSupport::Concern
|
2009-05-21 05:50:34 -04:00
|
|
|
|
2010-01-30 10:35:22 -05:00
|
|
|
include AbstractController::Compatibility
|
|
|
|
|
2009-05-21 05:50:34 -04:00
|
|
|
class ::ActionController::ActionControllerError < StandardError #:nodoc:
|
|
|
|
end
|
|
|
|
|
2010-03-02 20:20:13 -05:00
|
|
|
module ClassMethods
|
|
|
|
end
|
|
|
|
|
2009-05-01 20:27:44 -04:00
|
|
|
# Temporary hax
|
2009-05-11 20:07:05 -04:00
|
|
|
included do
|
2009-05-11 15:45:26 -04:00
|
|
|
::ActionController::UnknownAction = ::AbstractController::ActionNotFound
|
|
|
|
::ActionController::DoubleRenderError = ::AbstractController::DoubleRenderError
|
2009-05-28 10:49:02 -04:00
|
|
|
|
2010-03-02 20:20:13 -05:00
|
|
|
# ROUTES TODO: This should be handled by a middleware and route generation
|
|
|
|
# should be able to handle SCRIPT_NAME
|
|
|
|
self.config.relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT']
|
2009-05-28 10:49:02 -04:00
|
|
|
|
Got overhead down from 127 to 85. All tests pass:
* Tentatively replaced HeaderHash with SimpleHeaderHash, which does not preserve
case but does handle converting Arrays to Strings in to_hash. This requires
further discussion.
* Moved default_charset to ActionDispatch::Response to avoid having to hop over
to ActionController. Ideally, this would be a constant on AD::Response, but
some tests expect to be able to change it dynamically and I didn't want to change
them yet.
* Completely override #initialize from Rack::Response. Previously, it was creating
a HeaderHash, and then we were creating an entirely new one. There is no way to
call super without incurring the overhead of creating a HeaderHash.
* Override #write from Rack::Response. Its implementation tracks Content-Length,
and doing so adds additional overhead that could be mooted if other middleware
changes the body. It is more efficiently done at the top-level server.
* Change sending_file to an instance_variable instead of header inspection. In
general, if a state is important, it should be set as a property of the response
not reconstructed later.
* Set the Etag to @body instead of .body. AS::Cache.expand_cache_key handles
Arrays fine, and it's more efficient to let it handle the body parts, since
it is not forced to create a joined String.
* If we detect the default cache control case, just set it, rather than setting
the constituent parts and then running the normal (expensive) code to generate
the string.
2009-08-10 11:40:41 -04:00
|
|
|
class << self
|
|
|
|
delegate :default_charset=, :to => "ActionDispatch::Response"
|
|
|
|
end
|
2009-05-28 10:49:02 -04:00
|
|
|
|
2009-05-12 19:21:34 -04:00
|
|
|
# cattr_reader :protected_instance_variables
|
|
|
|
cattr_accessor :protected_instance_variables
|
2009-10-29 00:37:29 -04:00
|
|
|
self.protected_instance_variables = %w(@assigns @performed_redirect @performed_render
|
|
|
|
@variables_added @request_origin @url
|
|
|
|
@parent_controller @action_name
|
|
|
|
@before_filter_chain_aborted @_headers @_params
|
2010-01-15 15:44:27 -05:00
|
|
|
@_response)
|
2009-05-28 10:49:02 -04:00
|
|
|
|
2009-05-12 19:21:34 -04:00
|
|
|
# Controls the resource action separator
|
|
|
|
cattr_accessor :resource_action_separator
|
|
|
|
self.resource_action_separator = "/"
|
2009-05-28 10:49:02 -04:00
|
|
|
|
2009-05-14 20:25:10 -04:00
|
|
|
cattr_accessor :use_accept_header
|
|
|
|
self.use_accept_header = true
|
2009-05-15 20:49:11 -04:00
|
|
|
|
|
|
|
self.page_cache_directory = defined?(Rails.public_path) ? Rails.public_path : ""
|
|
|
|
|
2009-05-22 20:29:44 -04:00
|
|
|
# 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"
|
|
|
|
cattr_accessor :asset_host
|
2009-05-26 18:03:09 -04:00
|
|
|
|
|
|
|
cattr_accessor :ip_spoofing_check
|
|
|
|
self.ip_spoofing_check = true
|
2009-08-09 11:56:18 -04:00
|
|
|
|
|
|
|
cattr_accessor :trusted_proxies
|
2009-05-11 17:48:58 -04:00
|
|
|
end
|
2009-05-28 10:49:02 -04:00
|
|
|
|
2010-03-02 20:20:13 -05:00
|
|
|
def self.deprecated_config_accessor(option, message = nil)
|
|
|
|
deprecated_config_reader(option, message)
|
|
|
|
deprecated_config_writer(option, message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.deprecated_config_reader(option, message = nil)
|
|
|
|
message ||= "Reading #{option} directly from ActionController::Base is deprecated. " \
|
|
|
|
"Please read it from config.#{option}"
|
|
|
|
|
|
|
|
ClassMethods.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
|
|
def #{option}
|
|
|
|
ActiveSupport::Deprecation.warn #{message.inspect}
|
|
|
|
config.#{option}
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.deprecated_config_writer(option, message = nil)
|
|
|
|
message ||= "Setting #{option} directly on ActionController::Base is deprecated. " \
|
|
|
|
"Please set it on config.action_controller.#{option}"
|
|
|
|
|
|
|
|
ClassMethods.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
|
|
def #{option}=(val)
|
|
|
|
ActiveSupport::Deprecation.warn #{message.inspect}
|
|
|
|
config.#{option} = val
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
|
|
|
deprecated_config_writer :session_store
|
|
|
|
deprecated_config_writer :session_options
|
|
|
|
deprecated_config_accessor :relative_url_root, "relative_url_root is ineffective. Please stop using it"
|
|
|
|
|
2009-05-19 21:08:04 -04:00
|
|
|
# For old tests
|
|
|
|
def initialize_template_class(*) end
|
|
|
|
def assign_shortcuts(*) end
|
|
|
|
|
2009-05-20 18:33:08 -04:00
|
|
|
# TODO: Remove this after we flip
|
|
|
|
def template
|
2009-08-06 18:45:40 -04:00
|
|
|
@template ||= view_context
|
2009-05-26 15:06:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def process_action(*)
|
|
|
|
template
|
|
|
|
super
|
2009-05-20 18:33:08 -04:00
|
|
|
end
|
|
|
|
|
2009-05-11 17:48:58 -04:00
|
|
|
module ClassMethods
|
2009-05-28 10:49:02 -04:00
|
|
|
def consider_all_requests_local
|
2010-02-01 05:40:27 -05:00
|
|
|
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="
|
2010-02-09 20:23:48 -05:00
|
|
|
Rails.application.config.consider_all_requests_local = value
|
2010-02-01 05:40:27 -05:00
|
|
|
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="
|
2010-02-09 20:23:48 -05:00
|
|
|
Rails.application.config.allow_concurrency = value
|
2009-05-28 10:49:02 -04:00
|
|
|
end
|
|
|
|
|
2009-05-11 20:07:05 -04:00
|
|
|
def rescue_action(env)
|
|
|
|
raise env["action_dispatch.rescue.exception"]
|
|
|
|
end
|
2009-05-15 20:49:11 -04:00
|
|
|
|
|
|
|
# Defines the storage option for cached fragments
|
|
|
|
def cache_store=(store_option)
|
|
|
|
@@cache_store = ActiveSupport::Cache.lookup_store(store_option)
|
|
|
|
end
|
2009-05-01 20:27:44 -04:00
|
|
|
end
|
2009-05-28 10:49:02 -04:00
|
|
|
|
2010-02-01 05:40:27 -05:00
|
|
|
delegate :consider_all_requests_local, :consider_all_requests_local=,
|
|
|
|
:allow_concurrency, :allow_concurrency=, :to => :"self.class"
|
|
|
|
|
2009-04-27 21:21:26 -04:00
|
|
|
def render_to_body(options)
|
|
|
|
if options.is_a?(Hash) && options.key?(:template)
|
|
|
|
options[:template].sub!(/^\//, '')
|
|
|
|
end
|
2009-05-28 10:49:02 -04:00
|
|
|
|
2009-08-10 18:49:33 -04:00
|
|
|
options[:text] = nil if options.delete(:nothing) == true
|
|
|
|
options[:text] = " " if options.key?(:text) && options[:text].nil?
|
2009-05-11 15:04:43 -04:00
|
|
|
|
2009-08-10 18:49:33 -04:00
|
|
|
super || " "
|
2009-04-27 21:21:26 -04:00
|
|
|
end
|
2009-05-15 18:57:12 -04:00
|
|
|
|
|
|
|
def _handle_method_missing
|
|
|
|
method_missing(@_action_name.to_sym)
|
|
|
|
end
|
|
|
|
|
|
|
|
def method_for_action(action_name)
|
|
|
|
super || (respond_to?(:method_missing) && "_handle_method_missing")
|
2009-05-28 10:49:02 -04:00
|
|
|
end
|
|
|
|
|
2009-05-20 20:55:25 -04:00
|
|
|
def performed?
|
|
|
|
response_body
|
|
|
|
end
|
2009-05-26 15:14:50 -04:00
|
|
|
|
|
|
|
# ==== Request only view path switching ====
|
|
|
|
def append_view_path(path)
|
|
|
|
view_paths.push(*path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def prepend_view_path(path)
|
|
|
|
view_paths.unshift(*path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def view_paths
|
2009-08-06 18:45:40 -04:00
|
|
|
view_context.view_paths
|
2009-05-26 15:14:50 -04:00
|
|
|
end
|
2009-04-27 21:21:26 -04:00
|
|
|
end
|
2009-05-21 23:22:18 -04:00
|
|
|
end
|