mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-22 17:42:14 +08:00
Fix context.Copy race condition
This commit is contained in:
parent
7180f2ba62
commit
52958eb8c9
@ -83,6 +83,10 @@ func (c *Context) Copy() *Context {
|
||||
cp.Writer = &cp.writermem
|
||||
cp.index = abortIndex
|
||||
cp.handlers = nil
|
||||
cp.Keys = map[string]interface{}{}
|
||||
for k, v := range c.Keys {
|
||||
cp.Keys[k] = v
|
||||
}
|
||||
return &cp
|
||||
}
|
||||
|
||||
|
@ -307,6 +307,8 @@ func TestContextCopy(t *testing.T) {
|
||||
assert.Equal(t, cp.Keys, c.Keys)
|
||||
assert.Equal(t, cp.engine, c.engine)
|
||||
assert.Equal(t, cp.Params, c.Params)
|
||||
cp.Set("foo", "notBar")
|
||||
assert.False(t, cp.Keys["foo"] == c.Keys["foo"])
|
||||
}
|
||||
|
||||
func TestContextHandlerName(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user