add throttle discriminator to rack env

This commit is contained in:
blahed 2014-05-01 22:20:13 -04:00
parent 430672d8f4
commit 97dce48bfc
2 changed files with 5 additions and 3 deletions

View file

@ -32,9 +32,10 @@ module Rack
(count > current_limit).tap do |throttled|
if throttled
req.env['rack.attack.matched'] = name
req.env['rack.attack.match_type'] = :throttle
req.env['rack.attack.match_data'] = data
req.env['rack.attack.matched'] = name
req.env['rack.attack.match_discriminator'] = discriminator
req.env['rack.attack.match_type'] = :throttle
req.env['rack.attack.match_data'] = data
Rack::Attack.instrument(req)
end
end

View file

@ -32,6 +32,7 @@ describe 'Rack::Attack.throttle' do
last_request.env['rack.attack.matched'].must_equal 'ip/sec'
last_request.env['rack.attack.match_type'].must_equal :throttle
last_request.env['rack.attack.match_data'].must_equal({:count => 2, :limit => 1, :period => @period})
last_request.env['rack.attack.match_discriminator'].must_equal('1.2.3.4')
end
it 'should set a Retry-After header' do
last_response.headers['Retry-After'].must_equal @period.to_s