DEV: API to register custom request rate limiting conditions (#30239)

This commit adds the `add_request_rate_limiter` plugin API which allows plugins to add custom rate limiters on top of the default rate limiters which requests by a user's id or the request's IP address.

Example to add a rate limiter that rate limits all requests from Googlebot under the same rate limit bucket:

```
add_request_rate_limiter(
  identifier: :country,
  key: ->(request) { "country/#{DiscourseIpInfo.get(request.ip)[:country]}" },
  activate_when: ->(request) { DiscourseIpInfo.get(request.ip)[:country].present? },
)
```
This commit is contained in:
Alan Guo Xiang Tan
2024-12-23 09:57:18 +08:00
committed by GitHub
parent 259f537d02
commit 859d61003e
11 changed files with 470 additions and 57 deletions

View File

@@ -45,6 +45,7 @@ Rails.autoloaders.each do |autoloader|
"http" => "HTTP",
"gc_stat_instrumenter" => "GCStatInstrumenter",
"chat_sdk" => "ChatSDK",
"ip" => "IP",
)
end
Rails.autoloaders.main.ignore(