Skip to content

Commit a161176

Browse files
committed
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 `#[]`.
1 parent 60d4834 commit a161176

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ def call(env)
7373
if whitelisted?(req)
7474
@app.call(env)
7575
elsif blacklisted?(req)
76-
blacklisted_response[env]
76+
self.class.blacklisted_response.call(env)
7777
elsif throttled?(req)
78-
throttled_response[env]
78+
self.class.throttled_response.call(env)
7979
else
8080
tracked?(req)
8181
@app.call(env)

lib/rack/attack.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ def call(env)
9696
if whitelisted?(req)
9797
@app.call(env)
9898
elsif blacklisted?(req)
99-
self.class.blacklisted_response[env]
99+
self.class.blacklisted_response.call(env)
100100
elsif throttled?(req)
101-
self.class.throttled_response[env]
101+
self.class.throttled_response.call(env)
102102
else
103103
tracked?(req)
104104
@app.call(env)

0 commit comments

Comments
 (0)