Class: Aikido::Zen::Middleware::Throttler
- Inherits:
-
Object
- Object
- Aikido::Zen::Middleware::Throttler
- Defined in:
- lib/aikido/zen/middleware/throttler.rb
Overview
Middleware that rejects requests from clients that are making too many requests to a given endpoint, based in the runtime configuration in the Aikido dashboard.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, config: Aikido::Zen.config, settings: Aikido::Zen.runtime_settings, rate_limiter: Aikido::Zen::RateLimiter.new) ⇒ Throttler
constructor
A new instance of Throttler.
Constructor Details
#initialize(app, config: Aikido::Zen.config, settings: Aikido::Zen.runtime_settings, rate_limiter: Aikido::Zen::RateLimiter.new) ⇒ Throttler
Returns a new instance of Throttler.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/aikido/zen/middleware/throttler.rb', line 11 def initialize( app, config: Aikido::Zen.config, settings: Aikido::Zen.runtime_settings, rate_limiter: Aikido::Zen::RateLimiter.new ) @app = app @config = config @settings = settings @rate_limiter = rate_limiter end |
Instance Method Details
#call(env) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/aikido/zen/middleware/throttler.rb', line 23 def call(env) request = request_from(env) if should_throttle?(request) @config.rate_limited_responder.call(request) else @app.call(env) end end |