1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-23 21:07:03 +00:00

Update to version 8.5.8 | Read HISTORY.md

Former-commit-id: 82128ce7a2896a9a8bafd7a5268b0b42057fc21a
This commit is contained in:
kataras
2017-11-09 12:03:14 +02:00
parent 5a8b17f0e8
commit 2a0c6dade6
16 changed files with 480 additions and 29 deletions

View File

@@ -21,6 +21,49 @@ import (
"github.com/kataras/iris/context"
)
func calculateAssetValidator(vdir string, assetFn func(name string) ([]byte, error), namesFn func() []string) AssetValidator {
if len(vdir) > 0 {
if vdir[0] == '.' {
vdir = vdir[1:]
}
if vdir[0] == '/' || vdir[0] == os.PathSeparator { // second check for /something, (or ./something if we had dot on 0 it will be removed
vdir = vdir[1:]
}
}
// collect the names we are care for,
// because not all Asset used here, we need the vdir's assets.
allNames := namesFn()
var names []string
for _, path := range allNames {
// i.e: path = public/css/main.css
// check if path is the path name we care for
if !strings.HasPrefix(path, vdir) {
continue
}
names = append(names, path)
}
return func(reqPath string) bool {
reqPath = strings.TrimPrefix(reqPath, "/"+vdir)
for _, path := range names {
// in order to map "/" as "/index.html"
if path == "/index.html" && reqPath == "/" {
reqPath = "/index.html"
}
if path == vdir+reqPath {
return true
}
}
return false
}
}
// StaticEmbeddedHandler returns a Handler which can serve
// embedded into executable files.
//
@@ -766,7 +809,7 @@ func serveFile(ctx context.Context, fs http.FileSystem, name string, redirect bo
// can't use Redirect() because that would make the path absolute,
// which would be a problem running under StripPrefix
if strings.HasSuffix(ctx.Request().URL.Path, indexPage) {
localRedirect(ctx, "./")
localRedirect(ctx.ResponseWriter(), ctx.Request(), "./")
return "", http.StatusMovedPermanently
}
@@ -787,12 +830,12 @@ func serveFile(ctx context.Context, fs http.FileSystem, name string, redirect bo
url := ctx.Request().URL.Path
if d.IsDir() {
if url[len(url)-1] != '/' {
localRedirect(ctx, path.Base(url)+"/")
localRedirect(ctx.ResponseWriter(), ctx.Request(), path.Base(url)+"/")
return "", http.StatusMovedPermanently
}
} else {
if url[len(url)-1] == '/' {
localRedirect(ctx, "../"+path.Base(url))
localRedirect(ctx.ResponseWriter(), ctx.Request(), "../"+path.Base(url))
return "", http.StatusMovedPermanently
}
}
@@ -802,7 +845,7 @@ func serveFile(ctx context.Context, fs http.FileSystem, name string, redirect bo
if d.IsDir() {
url := ctx.Request().URL.Path
if url[len(url)-1] != '/' {
localRedirect(ctx, path.Base(url)+"/")
localRedirect(ctx.ResponseWriter(), ctx.Request(), path.Base(url)+"/")
return "", http.StatusMovedPermanently
}
}
@@ -885,12 +928,14 @@ func toHTTPError(err error) (msg string, httpStatus int) {
// localRedirect gives a Moved Permanently response.
// It does not convert relative paths to absolute paths like Redirect does.
func localRedirect(ctx context.Context, newPath string) {
if q := ctx.Request().URL.RawQuery; q != "" {
func localRedirect(w http.ResponseWriter, r *http.Request, newPath string) {
if q := r.URL.RawQuery; q != "" {
newPath += "?" + q
}
ctx.Header("Location", newPath)
ctx.StatusCode(http.StatusMovedPermanently)
w.Header().Set("Location", newPath)
w.WriteHeader(http.StatusMovedPermanently)
// ctx.Header("Location", newPath)
// ctx.StatusCode(http.StatusMovedPermanently)
}
func containsDotDot(v string) bool {