From e0763ba8e7cfe5860ebb1c5d24d4348b0dec1d73 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 6 Jan 2010 15:59:03 -0800 Subject: [PATCH] godoc: serve index.html in place of directory listing, when present R=gri CC=golang-dev https://golang.org/cl/181155 --- src/cmd/godoc/godoc.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go index 9331d2caef..e760d22307 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 }