mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-23 01:57:55 +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.Writer = &cp.writermem
|
||||||
cp.index = abortIndex
|
cp.index = abortIndex
|
||||||
cp.handlers = nil
|
cp.handlers = nil
|
||||||
|
cp.Keys = map[string]interface{}{}
|
||||||
|
for k, v := range c.Keys {
|
||||||
|
cp.Keys[k] = v
|
||||||
|
}
|
||||||
return &cp
|
return &cp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,6 +307,8 @@ func TestContextCopy(t *testing.T) {
|
|||||||
assert.Equal(t, cp.Keys, c.Keys)
|
assert.Equal(t, cp.Keys, c.Keys)
|
||||||
assert.Equal(t, cp.engine, c.engine)
|
assert.Equal(t, cp.engine, c.engine)
|
||||||
assert.Equal(t, cp.Params, c.Params)
|
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) {
|
func TestContextHandlerName(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user