messua/layer/rate_limit

Values

pub fn make_layer(
  requests: Int,
  over_seconds: Int,
  housekeep_every: Int,
) -> fn(
  minc.Incoming(state),
  fn(minc.Incoming(state)) -> Result(
    response.Response(mist.ResponseData),
    fail.Failure,
  ),
) -> Result(response.Response(mist.ResponseData), fail.Failure)

This makes an IP-based rate-limiting Layer that will allow requests requests from any given IP in the space of over_seconds seconds. Any more requests than that in a given time period will be automatically rejected with a 429 and not passed to the inner Handler.

The housekeep_every argument controls how often the map of timers is crawled through to prune expired ones. Larger values will result in less frequent pauses, but possibly more memory usage.

Search Document