]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: document ServeFile and FileServer index.html redirect behavior
authorBrad Fitzpatrick <bradfitz@golang.org>
Thu, 30 Apr 2015 20:24:58 +0000 (13:24 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 30 Apr 2015 20:42:58 +0000 (20:42 +0000)
Fixes #9876

Change-Id: I97a354fde827dfccc9e373fadea2e37d094439b0
Reviewed-on: https://go-review.googlesource.com/9538
Reviewed-by: Rob Pike <r@golang.org>
src/net/http/fs.go

index 40bf1b3ef381725acdabb1dc663c74bb70b7ed95..75720234c25d8083b40b3a37ec85f815fb6b0da2 100644 (file)
@@ -443,7 +443,13 @@ func localRedirect(w ResponseWriter, r *Request, newPath string) {
        w.WriteHeader(StatusMovedPermanently)
 }
 
-// ServeFile replies to the request with the contents of the named file or directory.
+// ServeFile replies to the request with the contents of the named
+// file or directory.
+//
+// As a special case, ServeFile redirects any request where r.URL.Path
+// ends in "/index.html" to the same path, without the final
+// "index.html". To avoid such redirects either modify the path or
+// use ServeContent.
 func ServeFile(w ResponseWriter, r *Request, name string) {
        dir, file := filepath.Split(name)
        serveFile(w, r, Dir(dir), file, false)
@@ -460,6 +466,10 @@ type fileHandler struct {
 // use http.Dir:
 //
 //     http.Handle("/", http.FileServer(http.Dir("/tmp")))
+//
+// As a special case, the returned file server redirects any request
+// ending in "/index.html" to the same path, without the final
+// "index.html".
 func FileServer(root FileSystem) Handler {
        return &fileHandler{root}
 }