Sha256: 765259b35625e809d3698ef7f2b87556343037a1a42cbc08895714b898f46b03

Contents?: true

Size: 1.59 KB

Versions: 5

Compression:

Stored size: 1.59 KB

Contents

require_relative '../context'

module Immunio
  module RedirectHook
    extend ActiveSupport::Concern

    included do
      alias_method_chain :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, loose_stack = Immunio::Context.context() # rubocop:disable Lint/UselessAssignment
            Immunio.run_hook! "redirect", "framework_redirect",
                              destination_url: loptions,
                              context_key: loose_context,
                              stack: loose_stack
          end
          Request.pause "plugin", "#{Module.nesting[0]}::#{__method__}" do
            redirect_to_without_immunio( options, response_status )
          end
        end
      end
  end
end

if Immunio::agent.plugin_enabled?("redirect") then
  ActionController::Base.send :include, Immunio::RedirectHook
  Immunio.logger.debug { "Redirect: All hooks installed." }
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
immunio-1.0.9 lib/immunio/plugins/redirect.rb
immunio-1.0.8 lib/immunio/plugins/redirect.rb
immunio-1.0.7 lib/immunio/plugins/redirect.rb
immunio-1.0.6 lib/immunio/plugins/redirect.rb
immunio-1.0.5 lib/immunio/plugins/redirect.rb