mirror of
https://github.com/golang/go
synced 2024-11-17 22:44:41 -07:00
net/http: merge IsDir checks in fs.go's serveFile function
Fixes #33385
This commit is contained in:
parent
fa7d40abe0
commit
3bf483808e
@ -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() {
|
if d.IsDir() {
|
||||||
url := r.URL.Path
|
url := r.URL.Path
|
||||||
|
// redirect if the directory name doesn't end in a slash
|
||||||
if url == "" || url[len(url)-1] != '/' {
|
if url == "" || url[len(url)-1] != '/' {
|
||||||
localRedirect(w, r, path.Base(url)+"/")
|
localRedirect(w, r, path.Base(url)+"/")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// use contents of index.html for directory, if present
|
// use contents of index.html for directory, if present
|
||||||
if d.IsDir() {
|
|
||||||
index := strings.TrimSuffix(name, "/") + indexPage
|
index := strings.TrimSuffix(name, "/") + indexPage
|
||||||
ff, err := fs.Open(index)
|
ff, err := fs.Open(index)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user