提交 81d17e08 作者: Matt Bell

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

上级 926b9646
...@@ -130,33 +130,37 @@ func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ...@@ -130,33 +130,37 @@ 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}) log.Debug("found index")
continue foundIndex = true
// return index page instead.
nd, err := i.ResolvePath(path + "/index.html")
if err != nil {
internalWebError(w, err)
return
}
dr, err := i.NewDagReader(nd)
if err != nil {
internalWebError(w, err)
return
}
// write to request
io.Copy(w, dr)
break
} }
log.Debug("found index") dirListing = append(dirListing, directoryItem{link.Size, link.Name})
// return index page instead. }
nd, err := i.ResolvePath(path + "/index.html")
if err != nil { if !foundIndex {
internalWebError(w, err) // template and return directory listing
return hndlr := webHandler{"listing": dirListing, "path": path}
} if err := i.dirList.Execute(w, hndlr); err != nil {
dr, err := i.NewDagReader(nd)
if err != nil {
internalWebError(w, err) internalWebError(w, err)
return return
} }
// write to request
io.Copy(w, dr)
}
// template and return directory listing
hndlr := webHandler{"listing": dirListing, "path": path}
if err := i.dirList.Execute(w, hndlr); err != nil {
internalWebError(w, err)
return
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论