Skip to content

Commit

Permalink
feat: deprecate throttled_response and blocklisted_response
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Jan 29, 2022
1 parent 8bf9d4e commit aaeff6d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
10 changes: 4 additions & 6 deletions lib/rack/attack/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@ class Configuration
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

Expand Down
6 changes: 4 additions & 2 deletions spec/acceptance/customizing_blocked_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@

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"
Expand Down
6 changes: 4 additions & 2 deletions spec/acceptance/customizing_throttled_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@

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"
Expand Down

0 comments on commit aaeff6d

Please sign in to comment.