class Rack::Throttle::Second

This rate limiter strategy throttles the application by defining a maximum number of allowed HTTP requests per second (by default, 1 request per second.

Note that this strategy doesn't use a sliding time window, but rather tracks requests per distinct second. This means that the throttling counter is reset every second.

@example Allowing up to 1 request/second

use Rack::Throttle::Second

@example Allowing up to 100 requests per second

use Rack::Throttle::Second, :max => 100

Public Class Methods

new(app, options = {}) click to toggle source

@param [#call] app @param [Hash{Symbol => Object}] options @option options [Integer] :max (1)

Calls superclass method
# File lib/rack/throttle/second.rb, line 22
def initialize(app, options = {})
  super
end

Public Instance Methods

max_per_second(request = nil) click to toggle source
# File lib/rack/throttle/second.rb, line 27
def max_per_second(request = nil)
  @max_per_second ||= options[:max_per_second] || options[:max] || 1
end
Also aliased as: max_per_window
max_per_window(request = nil)
Alias for: max_per_second

Protected Instance Methods

cache_key(request) click to toggle source

@param [Rack::Request] request @return [String]

Calls superclass method
# File lib/rack/throttle/second.rb, line 38
def cache_key(request)
  [super, Time.now.strftime('%Y-%m-%dT%H:%M:%S')].join(':')
end