GithubHelp home page GithubHelp logo

duration overwritten about elysia-rate-limit HOT 7 CLOSED

doroved avatar doroved commented on August 15, 2024
duration overwritten

from elysia-rate-limit.

Comments (7)

rayriffy avatar rayriffy commented on August 15, 2024 1

No that's not the behavior of rate limit at all. Rate limiting should be counted by time window, what you're asking right now is to give user a time out after certain request which is no longer a rate limiting anymore.

Thinking this scenario, with rate limit of 10 request with duration of 100 seconds

  1. (0 sec) Make 2 requests
  2. (400 sec) Make 7 request
  3. (800 sec) Make 1 request
  4. (801 sec) Make 1 request, get rate limited and waiting for 100 seconds
  5. (901 sec) Make 1 request

This is 900 seconds time window, not 100 seconds

from elysia-rate-limit.

doroved avatar doroved commented on August 15, 2024

Apparently, duration should be passed to the increment function

const { count, nextReset } = await options.context.increment(clientKey!)

from elysia-rate-limit.

doroved avatar doroved commented on August 15, 2024

Great, thank you.

from elysia-rate-limit.

doroved avatar doroved commented on August 15, 2024

@rayriffy , I think that Ratelimit-Reset should start counting after the requests run out.
Right now it triggers after the first request, which doesn't seem logical.
What do you think about this?

rateLimit({
  max: 10,
  duration: 100 * 1000
})

Ratelimit-Limit:
10
Ratelimit-Remaining:
7
Ratelimit-Reset:
75

from elysia-rate-limit.

doroved avatar doroved commented on August 15, 2024

No that's not the behavior of rate limit at all. Rate limiting should be counted by time window, what you're asking right now is to give user a time out after certain request which is no longer a rate limiting anymore.

Thinking this scenario, with rate limit of 10 request with duration of 100 seconds

  1. (0 sec) Make 2 requests
  2. (400 sec) Make 7 request
  3. (800 sec) Make 1 request
  4. (801 sec) Make 1 request, get rate limited and waiting for 100 seconds
  5. (901 sec) Make 1 request

This is 900 seconds time window, not 100 seconds

Thanks for the explanation, indeed, I hadn't thought of that)

In order not to create a new issue, let me ask here.
I see that the ...rest is passed to the generator.

clientKey = await options.generator(request, app.server, rest)

Earlier you added derived support to the generator and showed an example using elysia-ip.
I would like to be able to access cookie, path etc from Elysia in the generator. Is there any way we can throw these into the generator?

from elysia-rate-limit.

rayriffy avatar rayriffy commented on August 15, 2024

cookies are just http header, you can intercept and parse them via request

from elysia-rate-limit.

doroved avatar doroved commented on August 15, 2024

cookies are just http header, you can intercept and parse them via request.

Yes, I just didn't want to write my own parser function) Ok

from elysia-rate-limit.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.