mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
Merge pull request #63 from blahed/tag-env-with-discriminator
add throttle discriminator to rack env
This commit is contained in:
commit
3aa7e541a3
2 changed files with 5 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue