summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-01-06 15:59:03 -0800
committerRuss Cox <rsc@golang.org>2010-01-06 15:59:03 -0800
commite68cf688f20ba98daf38623279d230f2de02bae6 (patch)
treedf22f3b91a3439a4320ad654e624adcd06ece565
parent3fc4e330fb821a3ae63bf1405a64844bd0b11b62 (diff)
downloadgolang-e68cf688f20ba98daf38623279d230f2de02bae6.tar.gz
godoc: serve index.html in place of directory listing, when present
R=gri CC=golang-dev http://codereview.appspot.com/181155
-rw-r--r--src/cmd/godoc/godoc.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go
index 9331d2cae..e760d2230 100644
--- a/src/cmd/godoc/godoc.go
+++ b/src/cmd/godoc/godoc.go
@@ -943,6 +943,12 @@ func serveFile(c *http.Conn, r *http.Request) {
return
case ext == ".html":
+ if strings.HasSuffix(path, "/index.html") {
+ // We'll show index.html for the directory.
+ // Use the dir/ version as canonical instead of dir/index.html.
+ http.Redirect(c, r.URL.Path[0:len(r.URL.Path)-len("index.html")], http.StatusMovedPermanently)
+ return
+ }
serveHTMLDoc(c, r, path)
return
@@ -958,6 +964,10 @@ func serveFile(c *http.Conn, r *http.Request) {
}
if dir != nil && dir.IsDirectory() {
+ if index := path + "/index.html"; isTextFile(index) {
+ serveHTMLDoc(c, r, index)
+ return
+ }
serveDirectory(c, r, path)
return
}