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
Before hook check moved out of routes matching in dispatcher #464
Conversation
One side effect of moving the call to the before hook prior to route matching is that route params will no longer be available to before hooks. @cym0n - could you elaborate on what your plugin does and/or why you need to modify the request like you have in the test case in the pull request? |
It's a multilang plugin. Here's the code: As i said, I was afraid that a modification like this could have side-effect :-) I was thinking about a new status, different from halted, that could be configured in the Context to manage situations like this. What do you think about a solution like this? |
I added to the branch a test to keep an eye on this. |
New solution for the problem. I'll wait for feedback on this solution before doing some refactoring and documentation. |
Ping? |
I suspended my work on this because at the time there was the big refactoring about routes, redirects and forward. |
If it's meant to change the path, people should use |
My idea was to give the opportunity to develope plugins that can change App routing, using forward directive, keeping all the development inside Dancer2. |
While I see your point, I can't think of a single reason to do that other than reimplementing I think it would be useful to raise this again when there's an specific thing wished to be implemented. What do you think? |
Actually my Dancer2::Plugin::Multilang use that behaviour, exploiting the File Handler megasplat. |
I'm closing this issue for the following reasons:
You're more than welcomed to open a PR with a new rebased version and we could discuss it again. I hope that's okay. Thanks for understanding. |
Run the test in the branch: t/hook_changing_path.t
It will go well.
Now take it in a different directory and run it again (obviously still with Dancer2 in your @inc). It will fail.
It's a self contained test, why should it fail?
Problem is that the dispatcher runs before hooks during the route matching and the before hook we introduced change routes, modifying something we didn't configure (/prefix/configured) in something we did (/configured).
When the script is in the t directory this is not a problem because the Dancer2::Handler::File appends a megasplat route to the app's routes and the before hook can be triggered when testing /prefix/configured against it.
In a directory different from t, Dancer2 environment can't determinate a public directory (under t we have a public...) so the Dancer2::Handler::File can't register itself to the app and the megasplat can't come saving us.
I tried to make the before hook triggered before the route matching, but I'm not sure this is the right thing to do. It makes sense for you?
This is still very dirty code. I left all the old halted context management inside the loop, just copying it also beofre it. But I want your feedback about the question before refactoring.
Problem I exposed has bad side effects in real world. I have a plugin that fails dzil test for that. A good workaround is creating a public directory under the t, but it's a bit dirty...