1
0
mirror of https://github.com/astaxie/beego.git synced 2025-06-11 05:20:40 +00:00

Merge pull request #4096 from jianzhiyao/request_context

fix memory leak of request context
This commit is contained in:
Ming Deng
2020-07-27 18:04:37 +08:00
committed by GitHub
3 changed files with 30 additions and 0 deletions

View File

@ -327,6 +327,26 @@ func (input *BeegoInput) ResetParams() {
input.pvalues = input.pvalues[:0]
}
// ResetData: reset data
func (input *BeegoInput) ResetData() {
input.dataLock.Lock()
input.data = nil
input.dataLock.Unlock()
}
// ResetBody: reset body
func (input *BeegoInput) ResetBody() {
input.RequestBody = []byte{}
}
// Clear: clear all data in input
func (input *BeegoInput) Clear() {
input.ResetParams()
input.ResetData()
input.ResetBody()
}
// Query returns input data item string by a given string.
func (input *BeegoInput) Query(key string) string {
if val := input.Param(key); val != "" {

View File

@ -50,9 +50,15 @@ func NewOutput() *BeegoOutput {
// Reset init BeegoOutput
func (output *BeegoOutput) Reset(ctx *Context) {
output.Context = ctx
output.Clear()
}
// Clear: clear all data in output
func (output *BeegoOutput) Clear() {
output.Status = 0
}
// Header sets response header item string via given key.
func (output *BeegoOutput) Header(key, val string) {
output.Context.ResponseWriter.Header().Set(key, val)