class Nexaas::Throttle::Configuration
Attributes
An array of file extensions considered to be asset-related. Values are strings that will be matched against the request path. Paths that match will be not be throttled. Example: [“css”, “js”, “jpeg”, “jpg”, “png”] @return [Array]
An array of User Agents that should be ignored by the throttler. Values are regexes that will be matched against the request User-Agent. Example: [/[Gg]oogle/, /Amazon/] @return [Array]
How many requests a consumer can do during a window until he starts being throttled. Example: 60 @return [Integer]
The size of the throttle window. Example: 1.minute, 1.hour, 60(s) @return [Integer]
Redis hash configuration with the following default values:
- host => localhost - port => 6379 - db => 0 - namespace => nexaas:throttle
@return [Hash]
The class that will handle request identification. Each application handle with different domains on identifying a request, so they have to provide information on who is the requester based on their domain. This class MUST have the following interface: MyRequestIdentifier#initialize(request) MyRequestIdentifier#token Where MyRequestIdentifier#token must be a UNIQUE identifier from the requester. @return [Class]
Whether or not requests are throttled. @return [Boolean]
Whether or not requests are throttled. @return [Boolean]
Whether or not requests are tracked. @return [Boolean]
Whether or not requests are tracked. @return [Boolean]
Public Class Methods
# File lib/nexaas/throttle/configuration.rb, line 56 def initialize @throttle = true @track = true @period = 1.minute @limit = 60 @request_identifier = nil @redis_options = default_redis_options @ignored_user_agents = nil @assets_extensions = %w[css js jpg jpeg png gif woff ttf svg] end
Public Instance Methods
# File lib/nexaas/throttle/configuration.rb, line 67 def check! required_options.each do |option| raise ArgumentError, "You must provide a `#{option}` configuration." if send(option).blank? end end
# File lib/nexaas/throttle/configuration.rb, line 73 def redis_options=(options) options ||= {} @redis_options = default_redis_options.merge(options) end
Private Instance Methods
# File lib/nexaas/throttle/configuration.rb, line 84 def default_redis_options { host: "localhost", port: 6379, db: 0, namespace: "nexaas:throttle" } end
# File lib/nexaas/throttle/configuration.rb, line 80 def required_options %w(period limit request_identifier redis_options) end