Merge pull request #687 from metamaps/fix/rack-attack

disable 5 minute request limit on rack attack
This commit is contained in:
Devin Howard 2016-09-29 15:18:48 +08:00 committed by GitHub
commit ec8dbbb4a7

View file

@ -4,9 +4,9 @@ class Rack::Attack
# Throttle all requests by IP (60rpm) # Throttle all requests by IP (60rpm)
# #
# Key: "rack::attack:#{Time.now.to_i/:period}:req/ip:#{req.ip}" # Key: "rack::attack:#{Time.now.to_i/:period}:req/ip:#{req.ip}"
throttle('req/ip', :limit => 300, :period => 5.minutes) do |req| # throttle('req/ip', :limit => 300, :period => 5.minutes) do |req|
req.ip # unless req.path.start_with?('/assets') # req.ip # unless req.path.start_with?('/assets')
end # end
# Throttle POST requests to /login by IP address # Throttle POST requests to /login by IP address
# #
@ -32,7 +32,10 @@ class Rack::Attack
end end
end end
throttle('load_url_title/req/ip', :limit => 5, :period => 1.second) do |req| throttle('load_url_title/req/5mins/ip', :limit => 300, :period => 5.minutes) do |req|
req.ip if req.path == 'hacks/load_url_title'
end
throttle('load_url_title/req/1s/ip', :limit => 5, :period => 1.second) do |req|
# If the return value is truthy, the cache key for the return value # If the return value is truthy, the cache key for the return value
# is incremented and compared with the limit. In this case: # is incremented and compared with the limit. In this case:
# "rack::attack:#{Time.now.to_i/1.second}:load_url_title/req/ip:#{req.ip}" # "rack::attack:#{Time.now.to_i/1.second}:load_url_title/req/ip:#{req.ip}"