-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
🐛 [Bug]: There is a conflict between app.NewCtxFunc and app.Use #3319
Comments
Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
This is because when not using app.Use, HTTP -> customRequestHandler -> nextCustom (which executes the route handler directly); If you use middleware, testCustomCtx doesn't implement the c.Next() method, so it will call *DefaultCtx's c.Next() method by default, and the c.Next() method will call nextCustom again internally and then go to call the route handler. But here is the problem, because *DefaultCtx's Next method receiver is *DefaultCtx , he can't handle the JSON method implemented by CustomCtx, so your custom middleware fails. @ReneWerner87 @gaby @efectn Am I right? // Next executes the next method in the stack that matches the current route.
func (c *DefaultCtx) Next() error {
// Increment handler index
c.indexHandler++
// Did we execute all route handlers?
if c.indexHandler < len(c.route.Handlers) {
// Continue route stack
return c.route.Handlers[c.indexHandler](c)
}
// Continue handler stack
if c.app.newCtxFunc != nil {
_, err := c.app.nextCustom(c)
return err
}
_, err := c.app.next(c)
return err
} If you want to achieve the effect you want, maybe you need to customize a Next method belonging to testCustomCtx. I didn't do any specific experiments, you can try it or I will when I have time. @attains-cloud |
@ReneWerner87 @gaby @efectn As mentioned above, this issue may not be considered a bug, and perhaps we should add a hint to the documentation telling users how to use both |
just as a hint |
Bug Description
CustomCtx no effect when app.newCtxFunc and app.use simultaneously existing
How to Reproduce
Steps to reproduce the behavior:
Expected Behavior
app.NewCtxFunc and app.Use can coexist
Fiber Version
v3.0.0-beta.4
Code Snippet (optional)
Checklist:
The text was updated successfully, but these errors were encountered: