Skip to content

Retry-After header should maybe not be static #47

@Alge

Description

@Alge

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions