diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2012-12-05 02:21:44 -0800 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2012-12-05 02:21:44 -0800 |
commit | e905639af2fe947ff7e1e2331e9216032dff8b3e (patch) | |
tree | 12363a0b618b5cce5228779257036aa0c601e850 /actionpack/lib | |
parent | 4af9be089c345c58b6eae462226ca7190bc6bb73 (diff) | |
parent | 86e3aaab939a67536f007d1633ec19521dba15e9 (diff) | |
download | rails-e905639af2fe947ff7e1e2331e9216032dff8b3e.tar.gz rails-e905639af2fe947ff7e1e2331e9216032dff8b3e.tar.bz2 rails-e905639af2fe947ff7e1e2331e9216032dff8b3e.zip |
Merge pull request #8404 from freegenie/filter_redirects
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/metal/instrumentation.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/http/filter_redirect.rb | 37 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/http/response.rb | 1 |
4 files changed, 40 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/metal/instrumentation.rb b/actionpack/lib/action_controller/metal/instrumentation.rb index ca4ae532ca..d3aa8f90c5 100644 --- a/actionpack/lib/action_controller/metal/instrumentation.rb +++ b/actionpack/lib/action_controller/metal/instrumentation.rb @@ -60,7 +60,7 @@ module ActionController ActiveSupport::Notifications.instrument("redirect_to.action_controller") do |payload| result = super payload[:status] = response.status - payload[:location] = response.location + payload[:location] = response.filtered_location result end end diff --git a/actionpack/lib/action_dispatch.rb b/actionpack/lib/action_dispatch.rb index 1d716a3248..d002babee3 100644 --- a/actionpack/lib/action_dispatch.rb +++ b/actionpack/lib/action_dispatch.rb @@ -75,6 +75,7 @@ module ActionDispatch autoload :Parameters autoload :ParameterFilter autoload :FilterParameters + autoload :FilterRedirect autoload :Upload autoload :UploadedFile, 'action_dispatch/http/upload' autoload :URL diff --git a/actionpack/lib/action_dispatch/http/filter_redirect.rb b/actionpack/lib/action_dispatch/http/filter_redirect.rb new file mode 100644 index 0000000000..900ce1c646 --- /dev/null +++ b/actionpack/lib/action_dispatch/http/filter_redirect.rb @@ -0,0 +1,37 @@ +module ActionDispatch + module Http + module FilterRedirect + + FILTERED = '[FILTERED]'.freeze # :nodoc: + + def filtered_location + if !location_filter.empty? && location_filter_match? + FILTERED + else + location + end + end + + private + + def location_filter + if request.present? + request.env['action_dispatch.redirect_filter'] || [] + else + [] + end + end + + def location_filter_match? + location_filter.any? do |filter| + if String === filter + location.include?(filter) + elsif Regexp === filter + location.match(filter) + end + end + end + + end + end +end diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 11b7534ea4..0f808ac9cf 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -61,6 +61,7 @@ module ActionDispatch # :nodoc: cattr_accessor(:default_headers) include Rack::Response::Helpers + include ActionDispatch::Http::FilterRedirect include ActionDispatch::Http::Cache::Response include MonitorMixin |