Pleroma v1.0.6-7-gb9188361+dev Pleroma.Plugs.RateLimiter View Source

Configuration

A keyword list of rate limiters where a key is a limiter name and value is the limiter configuration. The basic configuration is a tuple where:

  • The first element: scale (Integer). The time scale in milliseconds.
  • The second element: limit (Integer). How many requests to limit in the time scale provided.

It is also possible to have different limits for unauthenticated and authenticated users: the keyword value must be a list of two tuples where the first one is a config for unauthenticated users and the second one is for authenticated.

To disable a limiter set its value to nil.

Example

config :pleroma, :rate_limit,
  one: {1000, 10},
  two: [{10_000, 10}, {10_000, 50}],
  foobar: nil

Here we have three limiters:

  • one which is not over 10req/1s
  • two which has two limits: 10req/10s for unauthenticated users and 50req/10s for authenticated users
  • foobar which is disabled

Usage

Inside a controller:

plug(Pleroma.Plugs.RateLimiter, :one when action == :one)
plug(Pleroma.Plugs.RateLimiter, :two when action in [:two, :three])

or inside a router pipiline:

pipeline :api do
  ...
  plug(Pleroma.Plugs.RateLimiter, :one)
  ...
end

Link to this section Summary

Link to this section Functions