diff options
Diffstat (limited to 'actionpack/lib/action_dispatch/http/filter_redirect.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/http/filter_redirect.rb | 37 |
1 files changed, 37 insertions, 0 deletions
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..25394fe5dd --- /dev/null +++ b/actionpack/lib/action_dispatch/http/filter_redirect.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +module ActionDispatch + module Http + module FilterRedirect + FILTERED = "[FILTERED]".freeze # :nodoc: + + def filtered_location # :nodoc: + if location_filter_match? + FILTERED + else + location + end + end + + private + + def location_filters + if request + request.get_header("action_dispatch.redirect_filter") || [] + else + [] + end + end + + def location_filter_match? + location_filters.any? do |filter| + if String === filter + location.include?(filter) + elsif Regexp === filter + location =~ filter + end + end + end + end + end +end |