Sha256: 6a59e81c5d258a32f31bd0eb5fdf3d2967aa9d8bfc8fcfa6d646ef04c4e4830b

Contents?: true

Size: 1.64 KB

Versions: 7

Compression:

Stored size: 1.64 KB

Contents

require_relative '../context'

module Immunio
  module RedirectHook
    extend ActiveSupport::Concern

    included do
      Immunio::Utils.alias_method_chain self, :redirect_to, :immunio if method_defined? :redirect_to
    end

    protected
      def redirect_to_with_immunio(options = {}, response_status = {})
        Immunio.logger.debug { "ActiveSupport checking redirect." }
        Request.time "plugin", "#{Module.nesting[0]}::#{__method__}" do
          # redirect_to excepts a variety of argument types
          # but the only one that creates a absolute URL redirect
          # is a string, so we only call the hook in that case.
          # However we have to call Proc arguments to determine
          # if they return a string...
          loptions = options
          if loptions.is_a? Proc then
            loptions = loptions.call
          end
          if loptions.is_a? String then
            _strict_context, loose_context, stack = Immunio::Context.context()
            Immunio.run_hook! "redirect", "framework_redirect",
                              destination_url: loptions,
                              context_key: loose_context,
                              stack: stack
          end
          Request.pause "plugin", "#{Module.nesting[0]}::#{__method__}" do
            redirect_to_without_immunio( options, response_status )
          end
        end
      end
  end
end

Immunio::Plugin.load 'ActionController (Redirect)',
                     feature: 'redirect',
                     hooks: %w( framework_redirect ) do |plugin|

  ActionController::Base.send :include, Immunio::RedirectHook

  plugin.loaded! ActionPack::VERSION::STRING
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
immunio-1.1.18 lib/immunio/plugins/redirect.rb
immunio-1.1.16 lib/immunio/plugins/redirect.rb
immunio-1.1.15 lib/immunio/plugins/redirect.rb
immunio-1.1.13 lib/immunio/plugins/redirect.rb
immunio-1.1.11 lib/immunio/plugins/redirect.rb
immunio-1.1.10 lib/immunio/plugins/redirect.rb
immunio-1.1.7 lib/immunio/plugins/redirect.rb