Fix context.Copy race condition

This commit is contained in:
Raphael Gavache 2017-07-14 19:36:21 +00:00
parent 7180f2ba62
commit 52958eb8c9
2 changed files with 6 additions and 0 deletions

View File

@ -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
}

View File

@ -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) {