rack attack throttle code example
Example 1: rack attack throttle
Rack::Attack.enabled = false
Example 2: rack attack throttle
Rack::Attack.throttle("requests by ip", limit: 5, period: 2) do |request|
request.ip
end
Rack::Attack.throttle('limit logins per email', limit: 6, period: 60) do |req|
if req.path == '/login' && req.post?
req.params['email'].to_s.downcase.gsub(/\s+/, "")
end
end
limit_proc = proc { |req| req.env["REMOTE_USER"] == "admin" ? 100 : 1 }
period_proc = proc { |req| req.env["REMOTE_USER"] == "admin" ? 1 : 60 }
Rack::Attack.throttle('request per ip', limit: limit_proc, period: period_proc) do |request|
request.ip
end