1
0
mirror of https://github.com/golang/go synced 2024-11-23 13:00:07 -07:00

net/http: merge IsDir checks in fs.go's serveFile function

Fixes #33385
This commit is contained in:
spacewander 2019-08-02 10:00:04 +08:00
parent fa7d40abe0
commit 3bf483808e

View File

@ -582,17 +582,15 @@ func serveFile(w ResponseWriter, r *Request, fs FileSystem, name string, redirec
}
}
// redirect if the directory name doesn't end in a slash
if d.IsDir() {
url := r.URL.Path
// redirect if the directory name doesn't end in a slash
if url == "" || url[len(url)-1] != '/' {
localRedirect(w, r, path.Base(url)+"/")
return
}
}
// use contents of index.html for directory, if present
if d.IsDir() {
// use contents of index.html for directory, if present
index := strings.TrimSuffix(name, "/") + indexPage
ff, err := fs.Open(index)
if err == nil {