1
0
mirror of https://github.com/golang/go synced 2024-09-30 22:48:32 -06:00

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

Fixes #9876

Change-Id: I97a354fde827dfccc9e373fadea2e37d094439b0
Reviewed-on: https://go-review.googlesource.com/9538
Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
Brad Fitzpatrick 2015-04-30 13:24:58 -07:00
parent f390135733
commit 125ed11c0a

View 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}
}