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

X-RateLimit-Reset

Open Xeus opened this issue 11 years ago • 2 comments

Hi, everything works great (thank you!) except that I get a 13-digit timestamp in my header, and I'm not sure that it's then setting the resetTime correctly. So I assume if I set resetTime to 10 in my middleware, then it should give me a 10-digit timestamp 10 seconds later than the time the request was made. No?

When testing this, I get throttled as expected but it immediately resets (I have the interval set to 2 requests/1 second). Am I confused here?

Xeus avatar Apr 23 '13 18:04 Xeus

Hey Ben. I use a bucket rate limiting approach here. You can imagine a bucket full of water (2 requests) at second 0, and reset time at second 1, which is when I will refill the bucket.

As you take more water out of the bucket during second 0, reset time will stay at second 1. At second 1, I'll refill the bucket and it'll be at 2 requests again and reset time will be second 2.

And the reset-time should be 13 digits as its the UTC milliseconds (not seconds):

('' + Date.now()).length
=> 13

Does that answer your question, or did I miss something?

ivolo avatar Apr 23 '13 18:04 ivolo

Sorry for the delay. Well, the problem I'm having is understanding resetTime, I think. I am guessing that once a requester is rate-limited, resetTime is a time in seconds that means how long the requester has to wait until he can make a request again, right? So if I set resetTime to 10, that should be 10 seconds until the requester can request again, no? And that's not happening, so I'm trying to figure out why not or what I need to set for this to work...?

Xeus avatar Apr 29 '13 00:04 Xeus