提交 81d17e08 作者: Matt Bell

cmd/ipfs: gatewayHandler: Fixed directory listing getting appended to index.html pages

上级 926b9646
...@@ -130,13 +130,11 @@ func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ...@@ -130,13 +130,11 @@ func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// storage for directory listing // storage for directory listing
var dirListing []directoryItem var dirListing []directoryItem
// loop through files // loop through files
foundIndex := false
for _, link := range nd.Links { for _, link := range nd.Links {
if link.Name != "index.html" { if link.Name == "index.html" {
dirListing = append(dirListing, directoryItem{link.Size, link.Name})
continue
}
log.Debug("found index") log.Debug("found index")
foundIndex = true
// return index page instead. // return index page instead.
nd, err := i.ResolvePath(path + "/index.html") nd, err := i.ResolvePath(path + "/index.html")
if err != nil { if err != nil {
...@@ -150,14 +148,20 @@ func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ...@@ -150,14 +148,20 @@ func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
// write to request // write to request
io.Copy(w, dr) io.Copy(w, dr)
break
} }
dirListing = append(dirListing, directoryItem{link.Size, link.Name})
}
if !foundIndex {
// template and return directory listing // template and return directory listing
hndlr := webHandler{"listing": dirListing, "path": path} hndlr := webHandler{"listing": dirListing, "path": path}
if err := i.dirList.Execute(w, hndlr); err != nil { if err := i.dirList.Execute(w, hndlr); err != nil {
internalWebError(w, err) internalWebError(w, err)
return return
} }
}
} }
func (i *gatewayHandler) postHandler(w http.ResponseWriter, r *http.Request) { func (i *gatewayHandler) postHandler(w http.ResponseWriter, r *http.Request) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论