go-chi / httprate Goto Github PK
View Code? Open in Web Editor NEWnet/http rate limiter middleware
License: MIT License
net/http rate limiter middleware
License: MIT License
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.
c.lastEvict
field used to amortize the cost of local counter's eviction doesn't seem to be ever updated.
Hi,
We were testing this library for use as we already use Chi and found an issue with the current implementation.
Currently's it first checks the status and then increments. This will create an error in the following scenario which can be replicated with a unit test.
If the request limit is say 25/sec If I get 50 requests simultaneously in the first second then it will let them through as for every request the initial value will be 0.
Instead, if we can have a way in which the current window can be incremented and retrieved along with the previous window then this can be fixed.
type LimitCounter interface {
// IncrAndGet is an atomic operation
IncrAndGet(key string, inc time.Time, get time.Time) (inc int64, get int64, err error)
}
We wanted to use Redis and the example which I stated is doable using INCR command.
Please let me know your thoughts.
Is there an easy way to use the existing httprate functionality but push it to the end resolution of the request/response chain instead of at the beginning.
We want to create a couple of open ended mutation endpoints that could be used maliciously so we want to limit the total number of bad requests in a short period of time, but not limit penalize a user who is submitted good data that returns 2XX responses.
Please, add examples with negative and zero limits and describe what they do.
@pkieltyka will you add a license file to this repo? As a practical matter, documentation on pkg.go.dev isn't viewable unless a suitable license is detected. It looks like, from the readme, that httprate is intended to be licensed under MIT. Thanks!
lets build github.com/go-chi/httprate-redis package name httprateredis
which implements the LimitCounter
interface so a counter may be shared across servers
LimitCounter
requireswindowLength
to determine whether to evict the key expired. The external counter implementation needs to hold the same duplicatewindowLength
as the Limit(_ , windowLength)
So far this middleware doesn't allow for custom limit handling like changing the response body and code, additional logging etc. Some other tools like https://github.com/didip/tollbooth have this feature. I think it would be nice to add it here. I can come up with a PR if the idea doesn't sound bad.
P.S. And thanks for the great work on Chi!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.