mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-16 05:16:35 +08:00
Using temporary variables to save c.Keys and c.Params to prevent them from changing during the copying process.
This commit is contained in:
parent
48e6fd723d
commit
a0ee71234a
15
context.go
15
context.go
@ -115,17 +115,22 @@ func (c *Context) Copy() *Context {
|
||||
Request: c.Request,
|
||||
engine: c.engine,
|
||||
}
|
||||
|
||||
cp.writermem.ResponseWriter = nil
|
||||
cp.Writer = &cp.writermem
|
||||
cp.index = abortIndex
|
||||
cp.handlers = nil
|
||||
cp.Keys = make(map[string]any, len(c.Keys))
|
||||
for k, v := range c.Keys {
|
||||
|
||||
cKeys := c.Keys
|
||||
cp.Keys = make(map[string]any, len(cKeys))
|
||||
for k, v := range cKeys {
|
||||
cp.Keys[k] = v
|
||||
}
|
||||
paramsCopy := make([]Param, len(c.Params))
|
||||
copy(paramsCopy, c.Params)
|
||||
cp.Params = paramsCopy
|
||||
|
||||
cParams := c.Params
|
||||
cp.Params = make([]Param, len(cParams))
|
||||
copy(cp.Params, cParams)
|
||||
|
||||
return &cp
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user