未验证 提交 7a48fbb6 编写于 作者: M Ming Deng 提交者: GitHub

Merge pull request #4066 from playHing/self-dev

Fix concurrent issue of context/input Query method
......@@ -333,8 +333,14 @@ func (input *BeegoInput) Query(key string) string {
return val
}
if input.Context.Request.Form == nil {
input.Context.Request.ParseForm()
input.dataLock.Lock()
if input.Context.Request.Form == nil {
input.Context.Request.ParseForm()
}
input.dataLock.Unlock()
}
input.dataLock.RLock()
defer input.dataLock.RUnlock()
return input.Context.Request.Form.Get(key)
}
......
......@@ -205,3 +205,13 @@ func TestParams(t *testing.T) {
}
}
func BenchmarkQuery(b *testing.B) {
beegoInput := NewInput()
beegoInput.Context = NewContext()
beegoInput.Context.Request, _ = http.NewRequest("POST", "http://www.example.com/?q=foo", nil)
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
beegoInput.Query("q")
}
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册