mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-04-27 15:07:41 +00:00
add throttle discriminator to rack env
This commit is contained in:
parent
430672d8f4
commit
97dce48bfc
2 changed files with 5 additions and 3 deletions
|
|
@ -32,9 +32,10 @@ module Rack
|
||||||
|
|
||||||
(count > current_limit).tap do |throttled|
|
(count > current_limit).tap do |throttled|
|
||||||
if throttled
|
if throttled
|
||||||
req.env['rack.attack.matched'] = name
|
req.env['rack.attack.matched'] = name
|
||||||
req.env['rack.attack.match_type'] = :throttle
|
req.env['rack.attack.match_discriminator'] = discriminator
|
||||||
req.env['rack.attack.match_data'] = data
|
req.env['rack.attack.match_type'] = :throttle
|
||||||
|
req.env['rack.attack.match_data'] = data
|
||||||
Rack::Attack.instrument(req)
|
Rack::Attack.instrument(req)
|
||||||
end
|
end
|
||||||
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.matched'].must_equal 'ip/sec'
|
||||||
last_request.env['rack.attack.match_type'].must_equal :throttle
|
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_data'].must_equal({:count => 2, :limit => 1, :period => @period})
|
||||||
|
last_request.env['rack.attack.match_discriminator'].must_equal('1.2.3.4')
|
||||||
end
|
end
|
||||||
it 'should set a Retry-After header' do
|
it 'should set a Retry-After header' do
|
||||||
last_response.headers['Retry-After'].must_equal @period.to_s
|
last_response.headers['Retry-After'].must_equal @period.to_s
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue