Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function for timeWindow #283

Closed
2 tasks done
AlexRMU opened this issue Jan 19, 2023 · 7 comments
Closed
2 tasks done

Function for timeWindow #283

AlexRMU opened this issue Jan 19, 2023 · 7 comments
Labels
enhancement New feature or request

Comments

@AlexRMU
Copy link

AlexRMU commented Jan 19, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

Add a function so that you can do a limit, for example 10 per minute AND 100 per hour AND 1000 per day.

Motivation

No response

Example

rateLimit: {
    max: async (req, key) => { /*... */ },
    timeWindow: async (req, key) => { /*... */ },
    // or
    max: {
        // key = window
        // value = max
        [60 * 1000]: 10,
        [60 * 60 * 1000]: async (req, key) => { /*... */ },
    }
}
@Uzlopak
Copy link
Contributor

Uzlopak commented Jan 19, 2023

Well this feature request raises questions. What are the headers on the response you gonna set? I think it is useful what you suggest, but needs more specs. So please elaborate.

@AlexRMU
Copy link
Author

AlexRMU commented Jan 19, 2023

Can be done as in nginx: https://serverfault.com/questions/976574/nginx-rate-limiting-using-multiple-rate-rules

You need to save the number of requests for the window separately

When requested:

  • The windows are sorted in ascending order
  • Max is checked for each in turn
  • If the max is exceeded, the headers for this window are returned

@gurgunday gurgunday added the enhancement New feature or request label Oct 20, 2023
@mcollina
Copy link
Member

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@AlexRMU
Copy link
Author

AlexRMU commented Dec 21, 2023

I tried, but realized that it would take a lot of architecture changes.
I can help with tips or a review.

@gurgunday
Copy link
Member

I think something similar can be achieved by using a function for the max parameter

@mindrunner
Copy link
Contributor

I added function feature for timeWindow. Please have a look :)

@gurgunday
Copy link
Member

Closed by #357

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants