httprate icon indicating copy to clipboard operation
httprate copied to clipboard

Allows limiter headers to be written via setting instead of sending them at all times #15

Open go-aegian opened this issue 2 years ago • 5 comments

The headers output by this middleware "X-RateLimit-Limit", "X-RateLimit-Remaining", "X-RateLimit-Reset", "Retry-After" should be output depending on a configuration for it.

go-aegian avatar Jun 14 '22 19:06 go-aegian

This PR would be very useful to me!

mwodrich avatar Jan 28 '23 04:01 mwodrich

@mwodrich so the request here is to make the response headers with ratelimit info optional? such that, the rate limits aren't returned to the client, and are invisible to clients...?

just wondering why you guys would like this?

pkieltyka avatar Feb 05 '23 22:02 pkieltyka

These headers are very useful for coordinating rates with a cooperative client that just needs to bound resource usage over time, but in a scenario where the rate limits are set to limit the impact of malicious actors, I don't believe it is valuable or appropriate to give them any information about the state or configuration of the rate limiter.

mwodrich avatar Feb 06 '23 20:02 mwodrich

Indeed, makes sense.

pkieltyka avatar Feb 06 '23 21:02 pkieltyka

@go-aegian I think it'd be fine to accept the new func WithHeaders(on bool) Option {}, though :)

VojtechVitek avatar Feb 27 '24 12:02 VojtechVitek

Please see https://github.com/go-chi/httprate/pull/31.

You can now omit all headers via:

httprate.Limit(
	1000,
	time.Minute,
	httprate.WithResponseHeaders(httprate.ResponseHeaders{}),
)

You can also customize or omit individual headers:

httprate.Limit(
            1000,
            time.Minute,
            httprate.WithResponseHeaders(httprate.ResponseHeaders{
                    Limit:      "", // omit
                    Remaining:  "", // omit
                    Increment:  "", // omit
                    Reset:      "X-RateLimit-Reset",
                    RetryAfter: "Retry-After",
            }),
    )

VojtechVitek avatar Jul 24 '24 13:07 VojtechVitek