Commit 125ed11c authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http: document ServeFile and FileServer index.html redirect behavior

Fixes #9876

Change-Id: I97a354fde827dfccc9e373fadea2e37d094439b0
Reviewed-on: https://go-review.googlesource.com/9538Reviewed-by: 's avatarRob Pike <r@golang.org>
parent f3901357
......@@ -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}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment