Merge pull request #93 from gsamokovarov/dont-rescue-nil

Avoid rescue nil in the default throttled response
This commit is contained in:
Aaron Suggs 2014-09-26 15:07:35 -04:00
commit a1cedbbc7e

View file

@ -82,7 +82,7 @@ class Rack::Attack
@notifier = ActiveSupport::Notifications if defined?(ActiveSupport::Notifications)
@blacklisted_response = lambda {|env| [403, {'Content-Type' => 'text/plain'}, ["Forbidden\n"]] }
@throttled_response = lambda {|env|
retry_after = env['rack.attack.match_data'][:period] rescue nil
retry_after = (env['rack.attack.match_data'] || {})[:period]
[429, {'Content-Type' => 'text/plain', 'Retry-After' => retry_after.to_s}, ["Retry later\n"]]
}