go-chi / go-chi/httprate

Retry-After header should maybe not be static

Open
#47 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
476
Forks
25
PR merge metrics
No merged PRs in 30d

Description

Currently, if I configure a rate limiter with the following code

```
r.Use(httprate.Limit(
10,
time.Minute,
httprate.WithResponseHeaders(httprate.ResponseHeaders{
Limit: "X-RateLimit-Limit",
Remaining: "X-RateLimit-Remaining",
Reset: "X-RateLimit-Reset",
RetryAfter: "Retry-After",
Increment: "", // omit
}),
))
```
After I hit the rate-limit, the `Retry-After` header is added to the request, but the value is always set to the window length, (in this case 60 seconds)

If the client sends 10 requests spaced out by 2 seconds and then sends a 11th one (which the rate-limiter should catch), shouldn't the `Retry-After` header contain `40` (the 10 first requests took 20 seconds to complete) instead of `60`, as the next request will be accepted 60 seconds after the initial request was made, not 60 seconds after the first failing request?

This would enable the client to wait for the exact time it needs to if it hits the rate limit.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.