mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-23 01:57:55 +08:00
router: handling file not found in StaticFS() to use Router's NoRoute handlers
This commit is contained in:
parent
a712f77d7a
commit
4983f1b3cf
@ -186,6 +186,18 @@ func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileS
|
||||
if nolisting {
|
||||
c.Writer.WriteHeader(404)
|
||||
}
|
||||
|
||||
file := c.Param("filepath")
|
||||
// Check existence of file
|
||||
if _, err := fs.Open(file); err != nil {
|
||||
c.handlers = group.engine.allNoRoute
|
||||
// Since we change our handler to Router's NotFound,
|
||||
// we need to reset the index
|
||||
c.index = -1
|
||||
serveError(c, 404, default404Body)
|
||||
return
|
||||
}
|
||||
|
||||
fileServer.ServeHTTP(c.Writer, c.Request)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user