Skip to content

Commit

Permalink
Close files opened in static file handler (gin-gonic#2118)
Browse files Browse the repository at this point in the history
* Close files opened in static file handler

* Do not use defer
  • Loading branch information
Shamus03 authored and ThomasObenaus committed Feb 19, 2020
1 parent 99f1d7d commit bfbb4ba
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion routergroup.go
Expand Up @@ -193,13 +193,15 @@ func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileS

file := c.Param("filepath")
// 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.handlers = group.engine.noRoute
// Reset index
c.index = -1
return
}
f.Close()

fileServer.ServeHTTP(c.Writer, c.Request)
}
Expand Down

0 comments on commit bfbb4ba

Please sign in to comment.