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

Retry-After header should maybe not be static #47

Open
Alge opened this issue Oct 29, 2024 · 0 comments
Open

Retry-After header should maybe not be static #47

Alge opened this issue Oct 29, 2024 · 0 comments

Comments

@Alge
Copy link

Alge commented Oct 29, 2024

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.

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

No branches or pull requests

1 participant