fix: Nil pointer dereference when context has no engine defined

Issue: #3178
This commit is contained in:
L. Jiang 2022-06-09 16:43:23 +08:00
parent 6c3a1d7063
commit 69a5091fd4

View File

@ -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 == nil || c.engine == nil || !c.engine.ContextWithFallback || c.Request == nil || c.Request.Context() == nil {
return nil
}
return c.Request.Context().Value(key)