Skip to content
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

Refactor Route Resolving and Dispatch #2425

Merged
merged 11 commits into from
Nov 10, 2020

Conversation

askvortsov1
Copy link
Sponsor Member

Prep for #2170

Changes proposed in this pull request:

  • Split DispatchRoute into middleware to figure out which route should be used, and another for actually executing it, so that we can use the route name in middleware in between
  • Similarly, logic in RouteCollection has been changed to return the route name as well as the handler function
  • CSRF extender has been changed to use the route name instead of path (path still works, but has been deprecated)

Reviewers should focus on:

  • Currently, if a CSRF-invalid request is made to a path that doesn't exist, CSRF will be evaluated before the route, so it'll be returned as a CSRF error. Now, it'll return a 404 before getting to the CSRF middleware. When we get to floodgate, this will similarly be an issue: not found will run before floodgate is. I don't think this is particularly problematic, but still something to think about.

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).

askvortsov1 and others added 7 commits October 30, 2020 00:23
This allows us to run middleware after we figure out which route we're on, but before we actually execute the controller for that route.
By making the route name explicitly available to middlewares, applications like CSRF and floodgate can set patterns based on route names instead of the path, which is an implementation detail.
- For these changes to actually be useful, we need to process ResolveRoute before ExecuteRoute, with the ability for people to add things in between
- We can also now add all middleware to the stack the same way, increasing extensibility.
Otherwise, `add`in the MiddlewareExtender doesn't work since it adds it after ExecuteRoute, which doesn't do anything.
[ci skip] [skip ci]
@clarkwinkelmann
Copy link
Member

clarkwinkelmann commented Nov 4, 2020

Doesn't the order of the middlewares cause the "not found" / "invalid method" error pages to not be translated into the user-selected language? Since SetLocale runs after ResolveRoute. I understand an exception from ResolveRoute will skip the next middlewares which would normally have been executed all the way down to ExecuteRoute.

@askvortsov1
Copy link
Sponsor Member Author

Ah didn't think of that case, pushed a fix. RequireAdministrativeAbility and ShareErrorsFromSession should be fine after route resolver, I think?

Copy link
Member

@clarkwinkelmann clarkwinkelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@askvortsov1 RequireAdministrativeAbility and ShareErrorsFromSession should be fine after route resolver, I think?

I think this should be fine the way it is, but haven't done any test on this PR.

@askvortsov1 askvortsov1 merged commit 0c95774 into master Nov 10, 2020
@askvortsov1 askvortsov1 deleted the as/separate-route-resolving-and-dispatch branch November 10, 2020 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants