|
@@ -185,11 +185,19 @@ func (group *RouterGroup) StaticFS(relativePath string, fs http.FileSystem) IRou
|
|
|
func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileSystem) HandlerFunc {
|
|
func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileSystem) HandlerFunc {
|
|
|
absolutePath := group.calculateAbsolutePath(relativePath)
|
|
absolutePath := group.calculateAbsolutePath(relativePath)
|
|
|
fileServer := http.StripPrefix(absolutePath, http.FileServer(fs))
|
|
fileServer := http.StripPrefix(absolutePath, http.FileServer(fs))
|
|
|
- _, nolisting := fs.(*onlyfilesFS)
|
|
|
|
|
|
|
+
|
|
|
return func(c *Context) {
|
|
return func(c *Context) {
|
|
|
- if nolisting {
|
|
|
|
|
|
|
+ file := c.Param("filepath")
|
|
|
|
|
+
|
|
|
|
|
+ // Check if file exists and/or if we have permission to access it
|
|
|
|
|
+ if _, err := fs.Open(file); err != nil {
|
|
|
c.Writer.WriteHeader(http.StatusNotFound)
|
|
c.Writer.WriteHeader(http.StatusNotFound)
|
|
|
|
|
+ c.handlers = group.engine.allNoRoute
|
|
|
|
|
+ // Reset index
|
|
|
|
|
+ c.index = -1
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
fileServer.ServeHTTP(c.Writer, c.Request)
|
|
fileServer.ServeHTTP(c.Writer, c.Request)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|