diff options
-rw-r--r-- | railties/lib/rails/application.rb | 8 | ||||
-rw-r--r-- | railties/lib/rails/configuration.rb | 8 | ||||
-rw-r--r-- | railties/test/application/middleware_test.rb | 30 |
3 files changed, 42 insertions, 4 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 8d64aff430..10fa63c303 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -239,7 +239,7 @@ module Rails middleware.use ::Rack::Lock unless config.allow_concurrency middleware.use ::Rack::Runtime - middleware.use ::Rack::MethodOverride + middleware.use ::Rack::MethodOverride unless config.middleware.api_only? 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) @@ -252,9 +252,9 @@ module Rails end middleware.use ::ActionDispatch::Callbacks - middleware.use ::ActionDispatch::Cookies + middleware.use ::ActionDispatch::Cookies unless config.middleware.api_only? - if config.session_store + if !config.middleware.api_only? && config.session_store if config.force_ssl && !config.session_options.key?(:secure) config.session_options[:secure] = true end @@ -267,7 +267,7 @@ module Rails middleware.use ::Rack::ConditionalGet middleware.use ::Rack::ETag, "no-cache" - if config.action_dispatch.best_standards_support + if !config.middleware.api_only? && config.action_dispatch.best_standards_support middleware.use ::ActionDispatch::BestStandardsSupport, config.action_dispatch.best_standards_support end end diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index f8ad17773a..0efa21d82c 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -9,6 +9,14 @@ module Rails class MiddlewareStackProxy #:nodoc: def initialize @operations = [] + @api_only = false + end + + attr_reader :api_only + alias :api_only? :api_only + + def api_only! + @api_only = true end def insert_before(*args, &block) diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index a1e6066b16..a190a31fc7 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -52,6 +52,36 @@ module ApplicationTests ], middleware end + test "api middleware stack" do + add_to_config "config.middleware.api_only!" + add_to_config "config.force_ssl = true" + add_to_config "config.action_dispatch.x_sendfile_header = 'X-Sendfile'" + + boot! + + assert_equal [ + "Rack::SSL", + "Rack::Sendfile", + "ActionDispatch::Static", + "Rack::Lock", + "ActiveSupport::Cache::Strategy::LocalCache", + "Rack::Runtime", + "ActionDispatch::RequestId", + "Rails::Rack::Logger", + "ActionDispatch::ShowExceptions", + "ActionDispatch::DebugExceptions", + "ActionDispatch::RemoteIp", + "ActionDispatch::Reloader", + "ActionDispatch::Callbacks", + "ActiveRecord::ConnectionAdapters::ConnectionManagement", + "ActiveRecord::QueryCache", + "ActionDispatch::ParamsParser", + "ActionDispatch::Head", + "Rack::ConditionalGet", + "Rack::ETag" + ], middleware + end + test "Rack::Sendfile is not included by default" do boot! |