mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-04-27 15:07:41 +00:00
Added track with limit/period options example to the README.md for clarity.
This commit is contained in:
parent
c51676d295
commit
1857f8dd57
1 changed files with 6 additions and 1 deletions
|
|
@ -188,11 +188,16 @@ end
|
||||||
### Tracks
|
### Tracks
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
# Track requests from a special user agent, supports limit and period options like throttle.
|
# Track requests from a special user agent.
|
||||||
Rack::Attack.track("special_agent") do |req|
|
Rack::Attack.track("special_agent") do |req|
|
||||||
req.user_agent == "SpecialAgent"
|
req.user_agent == "SpecialAgent"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Supports optional limit and period, triggers the notification only when the limit is reached.
|
||||||
|
Rack::Attack.track("special_agent", :limit 6, :period => 60.seconds) do |req|
|
||||||
|
req.user_agent == "SpecialAgent"
|
||||||
|
end
|
||||||
|
|
||||||
# Track it using ActiveSupport::Notification
|
# Track it using ActiveSupport::Notification
|
||||||
ActiveSupport::Notifications.subscribe("rack.attack") do |name, start, finish, request_id, req|
|
ActiveSupport::Notifications.subscribe("rack.attack") do |name, start, finish, request_id, req|
|
||||||
if req.env['rack.attack.matched'] == "special_agent" && req.env['rack.attack.match_type'] == :track
|
if req.env['rack.attack.matched'] == "special_agent" && req.env['rack.attack.match_type'] == :track
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue