Class: Grape::Attack::Throttle

Inherits:
Middleware::Base
  • Object
show all
Defined in:
lib/grape/attack/throttle.rb

Instance Method Summary collapse

Instance Method Details

#afterObject

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

#beforeObject



8
9
10
# File 'lib/grape/attack/throttle.rb', line 8

def before
  ::Grape::Attack::Limiter.new(env).call!
end