mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-04-27 15:07:41 +00:00
Delegate to class methods with forwardable
This commit is contained in:
parent
c3a077442a
commit
332dd4ff9e
1 changed files with 11 additions and 4 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
require 'rack'
|
require 'rack'
|
||||||
|
require 'forwardable'
|
||||||
|
|
||||||
class Rack::Attack
|
class Rack::Attack
|
||||||
autoload :Cache, 'rack/attack/cache'
|
autoload :Cache, 'rack/attack/cache'
|
||||||
|
|
@ -89,15 +90,21 @@ class Rack::Attack
|
||||||
def call(env)
|
def call(env)
|
||||||
req = Rack::Request.new(env)
|
req = Rack::Request.new(env)
|
||||||
|
|
||||||
if self.class.whitelisted?(req)
|
if whitelisted?(req)
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
elsif self.class.blacklisted?(req)
|
elsif blacklisted?(req)
|
||||||
self.class.blacklisted_response[env]
|
self.class.blacklisted_response[env]
|
||||||
elsif self.class.throttled?(req)
|
elsif throttled?(req)
|
||||||
self.class.throttled_response[env]
|
self.class.throttled_response[env]
|
||||||
else
|
else
|
||||||
self.class.tracked?(req)
|
tracked?(req)
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
extend Forwardable
|
||||||
|
def_delegators self, :whitelisted?,
|
||||||
|
:blacklisted?,
|
||||||
|
:throttled?,
|
||||||
|
:tracked?
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue