mirror of
https://github.com/cwinfo/matterbridge.git
synced 2025-09-06 12:34:10 +00:00
Update vendor
This commit is contained in:
39
vendor/github.com/labstack/echo/middleware/static.go
generated
vendored
39
vendor/github.com/labstack/echo/middleware/static.go
generated
vendored
@@ -3,7 +3,9 @@ package middleware
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/labstack/echo"
|
||||
)
|
||||
@@ -53,6 +55,9 @@ func Static(root string) echo.MiddlewareFunc {
|
||||
// See `Static()`.
|
||||
func StaticWithConfig(config StaticConfig) echo.MiddlewareFunc {
|
||||
// Defaults
|
||||
if config.Root == "" {
|
||||
config.Root = "." // For security we want to restrict to CWD.
|
||||
}
|
||||
if config.Skipper == nil {
|
||||
config.Skipper = DefaultStaticConfig.Skipper
|
||||
}
|
||||
@@ -62,26 +67,44 @@ func StaticWithConfig(config StaticConfig) echo.MiddlewareFunc {
|
||||
|
||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
p := c.Param("*")
|
||||
name := filepath.Join(config.Root, p)
|
||||
fi, err := os.Stat(name)
|
||||
if config.Skipper(c) {
|
||||
return next(c)
|
||||
}
|
||||
|
||||
p := c.Request().URL.Path
|
||||
if strings.HasSuffix(c.Path(), "*") { // When serving from a group, e.g. `/static*`.
|
||||
p = c.Param("*")
|
||||
}
|
||||
name := filepath.Join(config.Root, path.Clean("/"+p)) // "/"+ for security
|
||||
|
||||
fi, err := os.Stat(name)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
if config.HTML5 {
|
||||
if config.HTML5 && path.Ext(p) == "" {
|
||||
return c.File(filepath.Join(config.Root, config.Index))
|
||||
}
|
||||
return echo.ErrNotFound
|
||||
return next(c)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
if fi.IsDir() {
|
||||
if config.Browse {
|
||||
return listDir(name, c.Response())
|
||||
index := filepath.Join(name, config.Index)
|
||||
fi, err = os.Stat(index)
|
||||
|
||||
if err != nil {
|
||||
if config.Browse {
|
||||
return listDir(name, c.Response())
|
||||
}
|
||||
if os.IsNotExist(err) {
|
||||
return next(c)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return c.File(filepath.Join(name, config.Index))
|
||||
|
||||
return c.File(index)
|
||||
}
|
||||
|
||||
return c.File(name)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user