Close files opened in static file handler (#2118)

* Close files opened in static file handler

* Do not use defer
This commit is contained in:
Shamus Taylor 2019-10-31 09:52:02 -05:00 committed by thinkerou
parent 517eacb4f9
commit aabaccbba2
1 changed files with 3 additions and 1 deletions

View File

@ -193,13 +193,15 @@ func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileS
file := c.Param("filepath") file := c.Param("filepath")
// Check if file exists and/or if we have permission to access it // Check if file exists and/or if we have permission to access it
if _, err := fs.Open(file); err != nil { f, err := fs.Open(file)
if err != nil {
c.Writer.WriteHeader(http.StatusNotFound) c.Writer.WriteHeader(http.StatusNotFound)
c.handlers = group.engine.noRoute c.handlers = group.engine.noRoute
// Reset index // Reset index
c.index = -1 c.index = -1
return return
} }
f.Close()
fileServer.ServeHTTP(c.Writer, c.Request) fileServer.ServeHTTP(c.Writer, c.Request)
} }