diff options
author | José Valim <jose.valim@gmail.com> | 2011-09-27 00:44:18 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-09-27 00:44:18 -0700 |
commit | 9a7e2b8d44b80e3380fb5ab042a861e84c8fe35c (patch) | |
tree | 7ef01cf82a7e0603542073aeacb1a4a794047368 | |
parent | 01e5e2faebb4a8082d38eb585762dc16ce3698f7 (diff) | |
parent | cb5c39f8a0af78e933d1fe0456c112db1e97813f (diff) | |
download | rails-9a7e2b8d44b80e3380fb5ab042a861e84c8fe35c.tar.gz rails-9a7e2b8d44b80e3380fb5ab042a861e84c8fe35c.tar.bz2 rails-9a7e2b8d44b80e3380fb5ab042a861e84c8fe35c.zip |
Merge pull request #3141 from jsl/make_ssl_configurable
Make the Rack::SSL middleware configurable
-rw-r--r-- | railties/guides/source/configuring.textile | 2 | ||||
-rw-r--r-- | railties/lib/rails/application.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 4 | ||||
-rw-r--r-- | railties/test/application/middleware_test.rb | 8 |
4 files changed, 13 insertions, 3 deletions
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index cad2d03c23..41b53440f7 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -179,7 +179,7 @@ h4. Configuring Middleware Every Rails application comes with a standard set of middleware which it uses in this order in the development environment: -* +Rack::SSL+ Will force every request to be under HTTPS protocol. Will be available if +config.force_ssl+ is set to +true+. +* +Rack::SSL+ Will force every request to be under HTTPS protocol. Will be available if +config.force_ssl+ is set to +true+. Options passed to this can be configured by using +config.ssl_options+. * +ActionDispatch::Static+ is used to serve static assets. Disabled if +config.serve_static_assets+ is +true+. * +Rack::Lock+ Will wrap the app in mutex so it can only be called by a single thread at a time. Only enabled if +config.action_controller.allow_concurrency+ is set to +false+, which it is by default. * +ActiveSupport::Cache::Strategy::LocalCache+ Serves as a basic memory backed cache. This cache is not thread safe and is intended only for serving as a temporary memory cache for a single thread. diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 90d7d27af1..2e412147d3 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -154,7 +154,7 @@ module Rails if config.force_ssl require "rack/ssl" - middleware.use ::Rack::SSL + middleware.use ::Rack::SSL, config.ssl_options end if config.serve_static_assets diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 141b39fb4b..c363e53c10 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -10,7 +10,8 @@ module Rails :dependency_loading, :filter_parameters, :force_ssl, :helpers_paths, :logger, :preload_frameworks, :reload_plugins, :secret_token, :serve_static_assets, - :static_cache_control, :session_options, :time_zone, :whiny_nils + :ssl_options, :static_cache_control, :session_options, + :time_zone, :whiny_nils attr_writer :log_level attr_reader :encoding @@ -26,6 +27,7 @@ module Rails @serve_static_assets = true @static_cache_control = nil @force_ssl = false + @ssl_options = {} @session_store = :cookie_store @session_options = {} @time_zone = "UTC" diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index bed5ba503f..093cb6ca2a 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -69,6 +69,14 @@ module ApplicationTests assert middleware.include?("Rack::SSL") end + test "Rack::SSL is configured with options when given" do + add_to_config "config.force_ssl = true" + add_to_config "config.ssl_options = { :host => 'example.com' }" + boot! + + assert_equal AppTemplate::Application.middleware.first.args, [{:host => 'example.com'}] + end + test "removing Active Record omits its middleware" do use_frameworks [] boot! |