Sha256: 8622df35c3facc3edde89c003c84dce050dbe25a178c84a4192b6ff459be1fb9

Contents?: true

Size: 1.03 KB

Versions: 5

Compression:

Stored size: 1.03 KB

Contents

module Ahoy
  class BaseController < ApplicationController
    # skip all filters except for authlogic
    filters = _process_action_callbacks.map(&:filter) - [:load_authlogic]
    if Rails::VERSION::MAJOR >= 5
      skip_before_action(*filters, raise: false)
      skip_after_action(*filters, raise: false)
      skip_around_action(*filters, raise: false)
      before_action :verify_request_size
    elsif respond_to?(:skip_action_callback)
      skip_action_callback *filters
      before_action :verify_request_size
    else
      skip_filter *filters
      before_filter :verify_request_size
    end

    if respond_to?(:protect_from_forgery)
      protect_from_forgery with: :null_session, if: -> { Ahoy.protect_from_forgery }
    end

    protected

    def ahoy
      @ahoy ||= Ahoy::Tracker.new(controller: self, api: true)
    end

    def verify_request_size
      if request.content_length > Ahoy.max_content_length
        logger.info "[ahoy] Payload too large"
        render text: "Payload too large\n", status: 413
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ahoy_matey-1.6.1 app/controllers/ahoy/base_controller.rb
ahoy_matey-1.6.0 app/controllers/ahoy/base_controller.rb
ahoy_matey-1.5.5 app/controllers/ahoy/base_controller.rb
ahoy_matey-1.5.4 app/controllers/ahoy/base_controller.rb
ahoy_matey-1.5.3 app/controllers/ahoy/base_controller.rb