Class: Rack::Throttle::Hourly
- Inherits:
-
TimeWindow
- Object
- Limiter
- TimeWindow
- Rack::Throttle::Hourly
- Defined in:
- lib/rack/throttle/hourly.rb
Overview
This rate limiter strategy throttles the application by defining a maximum number of allowed HTTP requests per hour (by default, 3,600 requests per 60 minutes, which works out to an average of 1 request per second).
Note that this strategy doesn’t use a sliding time window, but rather tracks requests per distinct hour. This means that the throttling counter is reset every hour on the hour (according to the server’s local timezone).
Constant Summary
Constants inherited from Limiter
Limiter::CODE, Limiter::MESSAGE
Instance Attribute Summary
Attributes inherited from Limiter
Instance Method Summary collapse
-
#initialize(app, options = {}) ⇒ Hourly
constructor
A new instance of Hourly.
- #max_per_hour ⇒ Object (also: #max_per_window)
- #retry_after ⇒ Object
Methods inherited from TimeWindow
Methods inherited from Limiter
#allowed?, #blacklisted?, #call, #whitelisted?
Constructor Details
#initialize(app, options = {}) ⇒ Hourly
Returns a new instance of Hourly.
24 25 26 |
# File 'lib/rack/throttle/hourly.rb', line 24 def initialize(app, = {}) super end |
Instance Method Details
#max_per_hour ⇒ Object Also known as: max_per_window
29 30 31 |
# File 'lib/rack/throttle/hourly.rb', line 29 def max_per_hour @max_per_hour ||= [:max_per_hour] || [:max] || 3_600 end |
#retry_after ⇒ Object
35 36 37 |
# File 'lib/rack/throttle/hourly.rb', line 35 def retry_after "3600" # simplification, because the strategy is not sliding end |