4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-09-06 12:34:10 +00:00

Update vendor

This commit is contained in:
Wim
2017-06-06 00:01:05 +02:00
parent 2eecaccd1c
commit 3a183cb218
49 changed files with 534 additions and 1421 deletions

View File

@@ -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)
}
}