mirror of
https://github.com/kataras/iris.git
synced 2026-01-08 12:31:58 +00:00
fix #1882
This commit is contained in:
@@ -384,7 +384,6 @@ func FileServer(fs http.FileSystem, options DirOptions) context.Handler {
|
||||
// match using relative path (without the first '/' slash)
|
||||
// to keep consistency between the `PushTargets` behavior
|
||||
if regex.MatchString(indexAsset) {
|
||||
|
||||
// println("Regex Matched: " + indexAsset)
|
||||
if err = pusher.Push(path.Join(prefixURL, indexAsset), pushOpts); err != nil {
|
||||
break
|
||||
@@ -588,8 +587,13 @@ func DirList(ctx *context.Context, dirOptions DirOptions, dirName string, dir ht
|
||||
|
||||
name := toBaseName(d.Name())
|
||||
|
||||
upath := path.Join(ctx.Request().RequestURI, name)
|
||||
url := url.URL{Path: upath}
|
||||
u, err := url.Parse(ctx.Request().RequestURI) // clone url and remove query (#1882).
|
||||
if err != nil {
|
||||
return fmt.Errorf("name: %s: error: %w", name, err)
|
||||
}
|
||||
u.RawQuery = ""
|
||||
|
||||
upath := url.URL{Path: path.Join(u.String(), name)}
|
||||
|
||||
downloadAttr := ""
|
||||
if dirOptions.Attachments.Enable && !d.IsDir() {
|
||||
@@ -608,7 +612,7 @@ func DirList(ctx *context.Context, dirOptions DirOptions, dirName string, dir ht
|
||||
"<span style=\"width: 150px; float: left; display: inline-block;\">%s</span>"+
|
||||
"<a href=\"%s\"%s>%s</a>"+
|
||||
"</li>",
|
||||
d.Mode().String(), url.String(), downloadAttr, html.EscapeString(viewName))
|
||||
d.Mode().String(), upath.String(), downloadAttr, html.EscapeString(viewName))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -667,8 +671,13 @@ func DirListRich(opts ...DirListRichOptions) DirListFunc {
|
||||
|
||||
name := toBaseName(d.Name())
|
||||
|
||||
upath := path.Join(ctx.Request().RequestURI, name)
|
||||
url := url.URL{Path: upath}
|
||||
u, err := url.Parse(ctx.Request().RequestURI) // clone url and remove query (#1882).
|
||||
if err != nil {
|
||||
return fmt.Errorf("name: %s: error: %w", name, err)
|
||||
}
|
||||
u.RawQuery = ""
|
||||
|
||||
upath := url.URL{Path: path.Join(u.String(), name)}
|
||||
|
||||
viewName := name
|
||||
if d.IsDir() {
|
||||
@@ -679,7 +688,7 @@ func DirListRich(opts ...DirListRichOptions) DirListFunc {
|
||||
pageData.Files = append(pageData.Files, fileInfoData{
|
||||
Info: d,
|
||||
ModTime: d.ModTime().UTC().Format(http.TimeFormat),
|
||||
Path: url.String(),
|
||||
Path: upath.String(),
|
||||
RelPath: path.Join(ctx.Path(), name),
|
||||
Name: html.EscapeString(viewName),
|
||||
Download: shouldDownload,
|
||||
@@ -1128,8 +1137,10 @@ type file struct {
|
||||
info os.FileInfo
|
||||
}
|
||||
|
||||
var _ http.File = (*file)(nil)
|
||||
var _ cacheStoreFile = (*file)(nil)
|
||||
var (
|
||||
_ http.File = (*file)(nil)
|
||||
_ cacheStoreFile = (*file)(nil)
|
||||
)
|
||||
|
||||
func newFile(name string, fi os.FileInfo, algs map[string][]byte) *file {
|
||||
return &file{
|
||||
@@ -1243,8 +1254,10 @@ type dir struct {
|
||||
children []os.FileInfo // a slice of *fileInfo
|
||||
}
|
||||
|
||||
var _ os.FileInfo = (*dir)(nil)
|
||||
var _ http.File = (*dir)(nil)
|
||||
var (
|
||||
_ os.FileInfo = (*dir)(nil)
|
||||
_ http.File = (*dir)(nil)
|
||||
)
|
||||
|
||||
func (d *dir) Close() error { return nil }
|
||||
func (d *dir) Name() string { return d.baseName }
|
||||
|
||||
Reference in New Issue
Block a user