mirror of
https://github.com/golang/go
synced 2024-11-18 17:54:57 -07: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:
parent
f390135733
commit
125ed11c0a
@ -443,7 +443,13 @@ func localRedirect(w ResponseWriter, r *Request, newPath string) {
|
|||||||
w.WriteHeader(StatusMovedPermanently)
|
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) {
|
func ServeFile(w ResponseWriter, r *Request, name string) {
|
||||||
dir, file := filepath.Split(name)
|
dir, file := filepath.Split(name)
|
||||||
serveFile(w, r, Dir(dir), file, false)
|
serveFile(w, r, Dir(dir), file, false)
|
||||||
@ -460,6 +466,10 @@ type fileHandler struct {
|
|||||||
// use http.Dir:
|
// use http.Dir:
|
||||||
//
|
//
|
||||||
// http.Handle("/", http.FileServer(http.Dir("/tmp")))
|
// 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 {
|
func FileServer(root FileSystem) Handler {
|
||||||
return &fileHandler{root}
|
return &fileHandler{root}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user