mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-04-27 15:07:41 +00:00
Invoke {blacklisted,throttled}_response with #call
I have a response which is a class. While I can still have my class implement `#[]`, it does look a bit off. On the other side, having objects, responding to #call, that are not procs is pretty common. So I propose to invoke the responses with `#call` to let users override it with response objects, that respond to `#call` instead of `#[]`.
This commit is contained in:
parent
60d4834969
commit
a161176142
2 changed files with 4 additions and 4 deletions
|
|
@ -73,9 +73,9 @@ def call(env)
|
||||||
if whitelisted?(req)
|
if whitelisted?(req)
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
elsif blacklisted?(req)
|
elsif blacklisted?(req)
|
||||||
blacklisted_response[env]
|
self.class.blacklisted_response.call(env)
|
||||||
elsif throttled?(req)
|
elsif throttled?(req)
|
||||||
throttled_response[env]
|
self.class.throttled_response.call(env)
|
||||||
else
|
else
|
||||||
tracked?(req)
|
tracked?(req)
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
|
|
|
||||||
|
|
@ -96,9 +96,9 @@ class Rack::Attack
|
||||||
if whitelisted?(req)
|
if whitelisted?(req)
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
elsif blacklisted?(req)
|
elsif blacklisted?(req)
|
||||||
self.class.blacklisted_response[env]
|
self.class.blacklisted_response.call(env)
|
||||||
elsif throttled?(req)
|
elsif throttled?(req)
|
||||||
self.class.throttled_response[env]
|
self.class.throttled_response.call(env)
|
||||||
else
|
else
|
||||||
tracked?(req)
|
tracked?(req)
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue