Permalink
Browse files

Add config.middleware.api_only!

  • Loading branch information...
spastorino committed Mar 5, 2012
1 parent 9cd9276 commit c84d3276def77889fa7b5833ebc51919b349c6ae
@@ -239,7 +239,7 @@ def default_middleware_stack
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 @@ def default_middleware_stack
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 @@ def default_middleware_stack
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
@@ -9,6 +9,14 @@ module Configuration
class MiddlewareStackProxy #:nodoc:
@josevalim

josevalim Mar 5, 2012

Contributor

We need to remove this #:nodoc: and actually document this class. :)

@spastorino

spastorino Mar 5, 2012

Owner

Yes it's in our (@cantoniodasilva and me) TODO list ;)

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)
@@ -52,6 +52,36 @@ def app
], 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!

0 comments on commit c84d327

Please sign in to comment.