Sha256: 003ff149095ac4df882366826faee3d9b26df913470793e82099a99890e2bfb6

Contents?: true

Size: 1.66 KB

Versions: 5

Compression:

Stored size: 1.66 KB

Contents

require_relative '../context'

module Immunio
  module RedirectHook
    extend ActiveSupport::Concern

    included do
      if method_defined? :redirect_to
        Immunio::Utils.alias_method_chain self, :redirect_to, :immunio
      end
    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

5 entries across 5 versions & 1 rubygems

Version Path
immunio-2.0.4 lib/immunio/plugins/redirect.rb
immunio-2.0.3 lib/immunio/plugins/redirect.rb
immunio-2.0.2 lib/immunio/plugins/redirect.rb
immunio-1.2.1 lib/immunio/plugins/redirect.rb
immunio-1.1.19 lib/immunio/plugins/redirect.rb