class Rack::Congestion::Limiter

Attributes

app[RW]
env[R]
options[RW]

Public Class Methods

new(app, options = { }) click to toggle source
# File lib/rack/congestion/limiter.rb, line 7
def initialize(app, options = { })
  self.app = app
  self.options = options
end

Public Instance Methods

_call(env) click to toggle source
# File lib/rack/congestion/limiter.rb, line 16
def _call(env)
  @env = env
  request.allowed? ? app.call(env) : rejected_response
end
backoff() click to toggle source
# File lib/rack/congestion/limiter.rb, line 40
def backoff
  request.backoff.to_s rescue -1
end
call(env) click to toggle source
# File lib/rack/congestion/limiter.rb, line 12
def call(env)
  dup._call env
end
key() click to toggle source
# File lib/rack/congestion/limiter.rb, line 25
def key
  ->{ 'global' }
end
rejected_response() click to toggle source
# File lib/rack/congestion/limiter.rb, line 29
def rejected_response
  [
    429,
    {
      'Content-Type' => 'text/plain; charset=utf-8',
      'Retry-After' => backoff
    },
    ['Rate Limit Exceeded']
  ]
end
request() click to toggle source
# File lib/rack/congestion/limiter.rb, line 21
def request
  @request ||= Rack::Congestion::Request.new env, key, options
end