diff options
author | Jeremy Friesen <jeremy.n.friesen@gmail.com> | 2012-05-31 10:06:17 -0400 |
---|---|---|
committer | Jeremy Friesen <jeremy.n.friesen@gmail.com> | 2012-05-31 12:39:28 -0400 |
commit | 4791822368bf0b1238a096c353cd408c6f1fe8c4 (patch) | |
tree | 01cc7c11038ad05b7a62afb8fb75a5d946ccb775 /actionpack/lib/action_controller/metal | |
parent | c51fb024063b5369a8d99b8c6e582feaf6c5a366 (diff) | |
download | rails-4791822368bf0b1238a096c353cd408c6f1fe8c4.tar.gz rails-4791822368bf0b1238a096c353cd408c6f1fe8c4.tar.bz2 rails-4791822368bf0b1238a096c353cd408c6f1fe8c4.zip |
Extracted redirect logic from ActionController::Force::ClassMethods.force_ssl
Prior to this patch the existing .force_ssl method handles both defining
the filter and handling the logic for performing the redirect.
With this patch the logic for redirecting to the HTTPS protocol is
separated from the filter logic that determines if a redirect should
occur. By separating the two levels of behavior, an instance method
for ActionController (i.e. #force_ssl_redirect) is exposed and available
for more granular SSL enforcement.
Cleaned up indentation.
Diffstat (limited to 'actionpack/lib/action_controller/metal')
-rw-r--r-- | actionpack/lib/action_controller/metal/force_ssl.rb | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/actionpack/lib/action_controller/metal/force_ssl.rb b/actionpack/lib/action_controller/metal/force_ssl.rb index ac12cbb625..77d799a38a 100644 --- a/actionpack/lib/action_controller/metal/force_ssl.rb +++ b/actionpack/lib/action_controller/metal/force_ssl.rb @@ -40,15 +40,23 @@ module ActionController def force_ssl(options = {}) host = options.delete(:host) before_filter(options) do - unless request.ssl? - redirect_options = {:protocol => 'https://', :status => :moved_permanently} - redirect_options.merge!(:host => host) if host - redirect_options.merge!(:params => request.query_parameters) - flash.keep if respond_to?(:flash) - redirect_to redirect_options - end + force_ssl_redirect(host) end end end + + # Redirect the existing request to use the HTTPS protocol. + # + # ==== Parameters + # * <tt>host</tt> - Redirect to a different host name + def force_ssl_redirect(host = nil) + unless request.ssl? + redirect_options = {:protocol => 'https://', :status => :moved_permanently} + redirect_options.merge!(:host => host) if host + redirect_options.merge!(:params => request.query_parameters) + flash.keep if respond_to?(:flash) + redirect_to redirect_options + end + end end end |