feat: deprecate throttled_response and blocklisted_response

This commit is contained in:
Gonzalo 2022-01-29 15:09:54 -03:00
parent 8bf9d4efad
commit aaeff6d0ae
No known key found for this signature in database
GPG key ID: 319EB6E3DB0D60FA
3 changed files with 12 additions and 10 deletions

View file

@ -25,16 +25,14 @@ module Rack
attr_reader :blocklisted_response, :throttled_response # Keeping these for backwards compatibility
def blocklisted_response=(responder)
# TODO: uncomment in 7.0
# warn "[DEPRECATION] Rack::Attack.blocklisted_response is deprecated. "\
# "Please use Rack::Attack.blocklisted_responder instead."
warn "[DEPRECATION] Rack::Attack.blocklisted_response is deprecated. "\
"Please use Rack::Attack.blocklisted_responder instead."
@blocklisted_response = responder
end
def throttled_response=(responder)
# TODO: uncomment in 7.0
# warn "[DEPRECATION] Rack::Attack.throttled_response is deprecated. "\
# "Please use Rack::Attack.throttled_responder instead"
warn "[DEPRECATION] Rack::Attack.throttled_response is deprecated. "\
"Please use Rack::Attack.throttled_responder instead"
@throttled_response = responder
end

View file

@ -46,8 +46,10 @@ describe "Customizing block responses" do
assert_equal 403, last_response.status
Rack::Attack.blocklisted_response = lambda do |_env|
[503, {}, ["Blocked"]]
silence_warnings do
Rack::Attack.blocklisted_response = lambda do |_env|
[503, {}, ["Blocked"]]
end
end
get "/", {}, "REMOTE_ADDR" => "1.2.3.4"

View file

@ -68,8 +68,10 @@ describe "Customizing throttled response" do
assert_equal 429, last_response.status
Rack::Attack.throttled_response = lambda do |_req|
[503, {}, ["Throttled"]]
silence_warnings do
Rack::Attack.throttled_response = lambda do |_req|
[503, {}, ["Throttled"]]
end
end
get "/", {}, "REMOTE_ADDR" => "1.2.3.4"