Class: Grape::Attack::Throttle
- Inherits:
-
Middleware::Base
- Object
- Middleware::Base
- Grape::Attack::Throttle
- Defined in:
- lib/grape/attack/throttle.rb
Instance Method Summary collapse
-
#after ⇒ Object
Fix when github.com/ruby-grape/grape/issues/1069 For now we use route_setting to store :remaining value.
- #before ⇒ Object
Instance Method Details
#after ⇒ Object
Fix when github.com/ruby-grape/grape/issues/1069 For now we use route_setting to store :remaining value.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/grape/attack/throttle.rb', line 14 def after request = ::Grape::Attack::Request.new(env) return if ::Grape::Attack.config.disable.call return unless request.throttle? @app_response['X-RateLimit-Limit'] = request.context.route_setting(:throttle)[:max].to_s @app_response['X-RateLimit-Remaining'] = request.context.route_setting(:throttle)[:remaining].to_s @app_response['X-RateLimit-Reset'] = request.context.route_setting(:throttle)[:per].from_now.to_i.to_s @app_response end |