Closed TheAwiteb closed 2 years ago
I use 'static
lifetime, I think this is not good, I tried to solve in a way other than this but I couldn't
I don't think I understood, this seems difficult to me as I am a beginner
Basically, futures boil down do state machines. The async
keyword tries to make is as simple as possible to create futures but sometimes it introduces limitations because the Rust compiler can't guess what you want to do. If you want to know more, you should read this. My idea is to create a custom future that polls the response until it's ready and then inserts the headers. That should be possible with minimal overhead.
The second one is generics. Instead of storing a runtime variable you can describe the configuration by using generics. For the configuration this would mean this signature:
pub struct GovernorConfig<K: KeyExtractor, M: governor::middlewareRateLimitingMiddleware> {
// fields ...
}
Depending on the configuration this middleware could be NoOpMiddleware
(as default) or StateInformationMiddleware
.
Then you can implement the Service
trait twice, one impl for the default behavior and one impl for the headers that uses StateInformationMiddleware
.
That's already pretty advanced Rust, but I'm happy to help you with the implementation. And if I find some time I can give it a shot myself.
Feature moved to #20 #21
Ratelimit headers for TooManyRequest error only ( need help 🚁 )