Skip to content

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

@prasad83

Description

@prasad83

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions