-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce FromRequest::on_entry()
#480
Comments
Can you detail further why it's important that you know which route was taken in your example of rate-limiting? In I believe you can also implement what you're suggesting as a request guard. Then you'd simple need to add the type to the route's signature to get the functionality you're looking. This way, you also have the flexibility to order guards the way you'd like. |
@SergioBenitez : Yes. So I think I want
Instead, I'd like |
If you have a route that looks like this: #[(get(...)]
fn something(a: A, b: B, c: C, rl: RateLimiter) -> T {
...
} Then if the |
@SergioBenitez I don't think users should have to figure out the right order of elements, especially that nothing can enforce it, and mistakes would lead to weird bugs. That's why I think There are basically two classes of request guards: failable matches (that can prevent taking the route at all), and infallible utilities, and they are both used the same way, but the user has to keep their order straight. Hmmm... Maybe the macro could take care of the ordering internally. Like one of the could be marked / distinct and macro would try them in the right order. Is that possible? |
Hmmm... But then in my |
I believe the general notion being asked for here will eventually be answered by #749. Closing in favor of that issue. |
Feature Requests
Why you believe this feature is necessary.
Right now
FromRequest::from_request
logic can only operate before the route is taken, typically to decide if the route should be taken or not. It would make request guards more powerful if they were able to do some stuff after the route was actually taken.Convincing use-case
I have a rate-limiting type, and I'd like the rate-limiting logic to check rete limits after the actual route was matched and taken, but I don't want to have to call it everywhere manually.
Potentially this could be used to fix #466 by clearing the
Flash
only when route was taken.Why this feature can't or shouldn't exist outside of Rocket.
Rocket controls what gets called and when.
Notes
This could be implemented by adding new method to
FromRequest
with no-op default implementation and generated code calling it on all request guards before calling the handler function.Maybe
on_exit
would be useful too.The text was updated successfully, but these errors were encountered: