Update README

This commit is contained in:
Aaron Suggs 2012-08-08 15:09:41 -04:00
parent e7aa5f4abe
commit 5a9f991b6e

View file

@ -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.