[deploy] Throttle General Site Requests (#7418)

This commit is contained in:
Molly Struve 2020-04-23 08:58:27 -05:00 committed by GitHub
parent 02264a234d
commit edcd019e9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View file

@ -16,4 +16,10 @@ class Rack::Attack
request.env["HTTP_API_KEY"]
end
end
throttle("site_hits", limit: 100, period: 2) do |request|
if request.env["HTTP_FASTLY_CLIENT_IP"].present?
request.env["HTTP_FASTLY_CLIENT_IP"].to_s
end
end
end

View file

@ -5,6 +5,7 @@ describe Rack::Attack, type: :request, throttle: true do
redis_url = "redis://localhost:6379"
cache_db = ActiveSupport::Cache::RedisStore.new(redis_url)
allow(Rails).to receive(:cache) { cache_db }
cache_db.data.flushdb
end
describe "search_throttle" do