express-brute icon indicating copy to clipboard operation
express-brute copied to clipboard

Retrieve number of remaining requests

Open jonathan-roy opened this issue 6 years ago • 2 comments

Hi,

I'm using express-brute as a rate limiter for my API, allowing for example a maximum of 3600 requests per IP per hour. I would like to give some information regarding rate limit through headers on every response (even those that are not rate limited), especially the following ones:

  • RateLimit-Count: number of requests already received from the beginning of the time frame.
  • RateLimit-Reset: date when the time frame is reset. I know there is a 'nextValidRequestDate' argument provided in 'failCallback', but I can't see any way to get that information from a successful request.

Is there a way to do it?

PS: I'm using the in-memory store at the moment.

jonathan-roy avatar Apr 13 '18 09:04 jonathan-roy

Any updates on this from the maintainers? Much appreciated!

jhnferraris avatar Mar 11 '19 06:03 jhnferraris

This isn't a feature that's currently implemented, but I'd welcome pull requests with tests. My thought is we'd probably want something similar to the attachResetToRequest option that allows those stats to be attached to the request object as well (rather than just setting headers on the request directly).

AdamPflug avatar Mar 13 '19 19:03 AdamPflug