1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-23 02:38:35 +00:00

Call MultipartForm.RemoveAll when request finishes (#19606) (#19607)

This commit is contained in:
wxiaoguang
2022-05-05 22:13:59 +08:00
committed by GitHub
parent 7b18c67ac9
commit 46637b1164
6 changed files with 20 additions and 0 deletions

View File

@@ -288,6 +288,7 @@ func APIContexter() func(http.Handler) http.Handler {
},
Org: &APIOrganization{},
}
defer ctx.Close()
ctx.Req = WithAPIContext(WithContext(req, ctx.Context), &ctx)
ctx.csrf = Csrfer(csrfOpts, ctx.Context)

View File

@@ -71,6 +71,16 @@ type Context struct {
Org *Organization
}
// Close frees all resources hold by Context
func (ctx *Context) Close() error {
var err error
if ctx.Req != nil && ctx.Req.MultipartForm != nil {
err = ctx.Req.MultipartForm.RemoveAll() // remove the temp files buffered to tmp directory
}
// TODO: close opened repo, and more
return err
}
// TrHTMLEscapeArgs runs Tr but pre-escapes all arguments with html.EscapeString.
// This is useful if the locale message is intended to only produce HTML content.
func (ctx *Context) TrHTMLEscapeArgs(msg string, args ...string) string {
@@ -643,6 +653,8 @@ func Contexter() func(next http.Handler) http.Handler {
"RunModeIsProd": setting.IsProd,
},
}
defer ctx.Close()
// PageData is passed by reference, and it will be rendered to `window.config.pageData` in `head.tmpl` for JavaScript modules
ctx.PageData = map[string]interface{}{}
ctx.Data["PageData"] = ctx.PageData

View File

@@ -38,6 +38,8 @@ func PrivateContexter() func(http.Handler) http.Handler {
Data: map[string]interface{}{},
},
}
defer ctx.Close()
ctx.Req = WithPrivateContext(req, ctx)
next.ServeHTTP(ctx.Resp, ctx.Req)
})