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



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/grape/attack/throttle.rb', line 11

def after
  request = ::Grape::Attack::Request.new(env)

  return if ::Grape::Attack.config.disable.call
  return unless request.throttle?

  header('X-RateLimit-Limit', request.throttle_options.max.to_s)
  header('X-RateLimit-Reset', request.throttle_options.per.to_s)
  header('X-RateLimit-Remaining', request.throttle_options.remaining.to_s)

  @app_response
end

#beforeObject



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

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