AaronErhardt / actix-governor

A middleware for actix-web that provides rate-limiting backed by governor.
GNU General Public License v3.0
103 stars 21 forks source link

🐙: Rate limits headers #17

Closed TheAwiteb closed 2 years ago

TheAwiteb commented 2 years ago

There is no rate limits headers 😢

AaronErhardt commented 2 years ago

Maybe I'm wrong, but it looks to me like this isn't standardized yet. Yet, if someone wants to contribute an option for enabling reasonable non-standard headers, like x-ratelimit-limit, I'd be happy to merge this.

TheAwiteb commented 2 years ago

if someone wants to contribute an option for enabling reasonable non-standard headers, like x-ratelimit-limit, I'd be happy to merge this.

I'm trying to do this but I couldn't reach the max request limit and how many request are left, can you help me.

here

https://github.com/AaronErhardt/actix-governor/blob/main/src/lib.rs#L485-L488

and here

https://github.com/AaronErhardt/actix-governor/blob/main/src/lib.rs#L509-L518

AaronErhardt commented 2 years ago

What you need to do is to add a StateInformationMiddleware as fourth generic argument to the RateLimiter. Ideally, the default should still be NoOpMiddleware so you will likely have to add another generic type to GovernorMiddleware.

With the StateInformationMiddleware you should be able to get a StateSnapshot with all the information you need. You only need to match against Ok(state_snapshot) here: https://github.com/AaronErhardt/actix-governor/blob/main/src/lib.rs#L485

Let me know if there are any other questions :)

TheAwiteb commented 2 years ago

Let me know if there are any other questions :)

How can i fix this 🙂

Screenshot_select-area_20220424045104

TheAwiteb commented 2 years ago

How can i fix this slightly_smiling_face

yesssssss i solve it with with_middleware

TheAwiteb commented 2 years ago

I did a PR #18 but it's incomplete, it just needs to bring the response here

https://github.com/TheAwiteb/actix-governor/blob/a910c7981f5c243d86fc7f5184b18d4bee846466/src/lib.rs#L487-L501

TheAwiteb commented 2 years ago

Fix in #21