]> Cypherpunks repositories - gostls13.git/commitdiff
godoc: serve index.html in place of directory listing, when present
authorRuss Cox <rsc@golang.org>
Wed, 6 Jan 2010 23:59:03 +0000 (15:59 -0800)
committerRuss Cox <rsc@golang.org>
Wed, 6 Jan 2010 23:59:03 +0000 (15:59 -0800)
R=gri
CC=golang-dev
https://golang.org/cl/181155

src/cmd/godoc/godoc.go

index 9331d2caef48e85913d8e5ea7db872186cc81988..e760d22307cb6269abac6d4b5c725784564f9f86 100644 (file)
@@ -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
        }