diff --git a/context.go b/context.go index b1ad95e6..e358badc 100644 --- a/context.go +++ b/context.go @@ -1195,7 +1195,7 @@ func (c *Context) Value(key any) any { return val } } - if !c.engine.ContextWithFallback || c.Request == nil || c.Request.Context() == nil { + if c.engine != nil && !c.engine.ContextWithFallback || c.Request == nil || c.Request.Context() == nil { return nil } return c.Request.Context().Value(key) diff --git a/context_test.go b/context_test.go index 6c0be544..7aeac45a 100644 --- a/context_test.go +++ b/context_test.go @@ -2294,3 +2294,9 @@ func TestContextAddParam(t *testing.T) { assert.Equal(t, ok, true) assert.Equal(t, value, v) } + +func TestRetrieveValueNoEngineInContext(t *testing.T) { + c := &Context{} + v := c.Value("foo") + assert.Nil(t, v) +}