mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 03:20:57 +00:00
Merge pull request #4066 from playHing/self-dev
Fix concurrent issue of context/input Query method
This commit is contained in:
commit
7a48fbb698
@ -332,9 +332,15 @@ func (input *BeegoInput) Query(key string) string {
|
||||
if val := input.Param(key); val != "" {
|
||||
return val
|
||||
}
|
||||
if input.Context.Request.Form == nil {
|
||||
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")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user