8000 🐛 [Bug]: Custom context not carried forward with middleware. · Issue #3397 · gofiber/fiber · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

🐛 [Bug]: Custom context not carried forward with middleware. #3397

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

Open
3 tasks done
prasad83 opened this issue Apr 8, 2025 · 3 comments
Open
3 tasks done

🐛 [Bug]: Custom context not carried forward with middleware. #3397

prasad83 opened this issue Apr 8, 2025 · 3 comments
Milestone

Comments

@prasad83
Copy link
prasad83 commented Apr 8, 2025

Bug Description

Issue 1

I had to use the following signature for custom context

type MyContext struct {
	fiber.DefaultCtx
}

app.NewCtxFunc(func(app *fiber.App) fiber.CustomCtx { /* correction: fiber.Ctx is documented */
    return &MyContext{
        DefaultCtx: *fiber.NewDefaultCtx(app), /* correction: Ctx is documented */
    }
})

Issue 2

app := fiber.New()

app.NewCtxFunc(func(app *fiber.App) fiber.CustomCtx {
    return &MyContext{
        DefaultCtx: *fiber.NewDefaultCtx(app),
    }
})

app.Use(logger.New()) /* when used MyContext is not carried forward */

app.Get("/", func(c fiber.Ctx) error {
    myCtx := c.(*MyContext)
}

app.Listen(":8080")

panic: as c here is *DefaultCtx

How to Reproduce

Run and make request http://localhost:8080/

Expected Behavior

myCtx := c.(*MyContext)

this should work even when middleware is used.

Fiber Version

3.0.0-beta4

Code Snippet (optional)

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.
Copy link
welcome bot commented Apr 8, 2025

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

@ReneWerner87
Copy link
Member

we will check this in the #3296 PR
there we rewrote the custom context initiailisation

@ReneWerner87 ReneWerner87 added the v3 label Apr 8, 2025
@ReneWerner87 ReneWerner87 added this to v3 Apr 8, 2025
@ReneWerner87 ReneWerner87 added this to the v3 milestone Apr 8, 2025
@pjebs
Copy link
Contributor
pjebs commented Apr 11, 2025

What if embedded Defaultcontext keeps a reference to the custom context so it can refer to it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

3 participants
0