diff --git a/context/input.go b/context/input.go index 7b522c36..385549c1 100644 --- a/context/input.go +++ b/context/input.go @@ -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) } diff --git a/context/input_test.go b/context/input_test.go index db812a0f..3a6c2e7b 100644 --- a/context/input_test.go +++ b/context/input_test.go @@ -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") + } + }) +}