mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-26 17:46:34 +03:00
Added Request.RemoveMultipartFormFiles for removing temporary files created during reading multipart/form-data request
This commit is contained in:
@@ -220,9 +220,6 @@ var ErrNoMultipartForm = errors.New("request has no multipart/form-data Content-
|
||||
//
|
||||
// Returns ErrNoMultipartForm if request's content-type
|
||||
// isn't 'multipart/form-data'.
|
||||
//
|
||||
// The caller must call RemoveAll on the returned form in order to remove
|
||||
// all temporary files associated with the returned form.
|
||||
func (req *Request) MultipartForm() (*multipart.Form, error) {
|
||||
if req.multipartForm != nil {
|
||||
return req.multipartForm, nil
|
||||
@@ -268,7 +265,18 @@ func (req *Request) clearSkipHeader() {
|
||||
req.parsedURI = false
|
||||
req.postArgs.Reset()
|
||||
req.parsedPostArgs = false
|
||||
req.multipartForm = nil
|
||||
req.RemoveMultipartFormFiles()
|
||||
}
|
||||
|
||||
// RemoveMultipartFormFiles removes multipart/form-data temporary files
|
||||
// associated with the request.
|
||||
func (req *Request) RemoveMultipartFormFiles() {
|
||||
if req.multipartForm != nil {
|
||||
// Do not check for error, since these files may be deleted or moved
|
||||
// to new places by user code.
|
||||
req.multipartForm.RemoveAll()
|
||||
req.multipartForm = nil
|
||||
}
|
||||
}
|
||||
|
||||
// Reset clears response contents.
|
||||
@@ -283,6 +291,10 @@ func (resp *Response) clearSkipHeader() {
|
||||
}
|
||||
|
||||
// Read reads request (including body) from the given r.
|
||||
//
|
||||
// RemoveMultipartFormFiles or Reset must be called after
|
||||
// reading multipart/form-data request in order to delete temporarily
|
||||
// uploaded files.
|
||||
func (req *Request) Read(r *bufio.Reader) error {
|
||||
return req.ReadLimitBody(r, 0)
|
||||
}
|
||||
@@ -293,6 +305,10 @@ const defaultMaxInMemoryFileSize = 16 * 1024 * 1024
|
||||
//
|
||||
// If maxBodySize > 0 and the body size exceeds maxBodySize,
|
||||
// then ErrBodyTooLarge is returned.
|
||||
//
|
||||
// RemoveMultipartFormFiles or Reset must be called after
|
||||
// reading multipart/form-data request in order to delete temporarily
|
||||
// uploaded files.
|
||||
func (req *Request) ReadLimitBody(r *bufio.Reader, maxBodySize int) error {
|
||||
req.clearSkipHeader()
|
||||
err := req.Header.Read(r)
|
||||
|
||||
@@ -839,13 +839,8 @@ func (s *Server) serveConn(c net.Conn) error {
|
||||
ctx.Response.Reset()
|
||||
s.Handler(ctx)
|
||||
|
||||
if ctx.Request.multipartForm != nil {
|
||||
// Remove temporary files, which may be uploaded during the request.
|
||||
// Do not check for error, since these files may be deleted or moved
|
||||
// to new places by RequestHandler.
|
||||
ctx.Request.multipartForm.RemoveAll()
|
||||
ctx.Request.multipartForm = nil
|
||||
}
|
||||
// Remove temporary files, which may be uploaded during the request.
|
||||
ctx.Request.RemoveMultipartFormFiles()
|
||||
|
||||
errMsg = ctx.timeoutErrMsg
|
||||
if len(errMsg) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user