mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
Update README
This commit is contained in:
parent
e7aa5f4abe
commit
5a9f991b6e
1 changed files with 8 additions and 1 deletions
|
|
@ -60,7 +60,9 @@ Note that `req` is a [Rack::Request](http://rack.rubyforge.org/doc/classes/Rack/
|
|||
|
||||
# Throttle requests to 5 requests per second per ip
|
||||
Rack::Attack.throttle('req/ip', :limit => 5, :period => 1.second) do |req|
|
||||
# If the return value is truthy, the cache key for "rack::attack:req/ip:#{req.ip}" is incremented and checked.
|
||||
# If the return value is truthy, the cache key for
|
||||
# "rack::attack:#{Time.now.to_i/1.second}:req/ip:#{req.ip}"
|
||||
# is incremented and compared with the limit.
|
||||
# If falsy, the cache key is neither incremented or checked.
|
||||
req.ip
|
||||
end
|
||||
|
|
@ -100,6 +102,11 @@ Similarly for blacklisted responses:
|
|||
[ 503, {}, ['Blocked']]
|
||||
end
|
||||
|
||||
For responses that did not exceed a throttle limit, Rack::Attack annotates the environment with match data.
|
||||
For example, in out `reqs/ip` throttle above, a matching request would have:
|
||||
|
||||
request.env['rack.attack.throttle_data']['req/ip'] # => { :period => 1, :limit => 5, :count => n }
|
||||
|
||||
## Logging & Instrumentation
|
||||
|
||||
Rack::Attack uses the [ActiveSupport::Notifications](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html) API if available.
|
||||
|
|
|
|||
Loading…
Reference in a new issue