1
0
mirror of https://github.com/golang/go synced 2024-11-14 22:30:26 -07:00

net/http: correct doc for ServeFileFS

The documentation of ServeFileFS was partly copied from ServeFile
in CL 513956, however it's not exact. This CL fixes some typos, also
removes obsolete comment for name param.

For consistency, also adds godoc link for ServeFile and ServeContent.

Fixes #66578

Change-Id: I87147d72c533d46284f06ef20b37fdafa8706710
Reviewed-on: https://go-review.googlesource.com/c/go/+/575016
Reviewed-by: Than McIntosh <thanm@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
This commit is contained in:
Jes Cok 2024-03-28 22:33:37 +08:00 committed by Than McIntosh
parent 8f618c1f53
commit bb523c9542

View File

@ -747,7 +747,7 @@ func localRedirect(w ResponseWriter, r *Request, newPath string) {
// If the provided file or directory name is a relative path, it is
// interpreted relative to the current directory and may ascend to
// parent directories. If the provided name is constructed from user
// input, it should be sanitized before calling ServeFile.
// input, it should be sanitized before calling [ServeFile].
//
// As a precaution, ServeFile will reject requests where r.URL.Path
// contains a ".." path element; this protects against callers who
@ -779,22 +779,20 @@ func ServeFile(w ResponseWriter, r *Request, name string) {
// ServeFileFS replies to the request with the contents
// of the named file or directory from the file system fsys.
//
// If the provided file or directory name is a relative path, it is
// interpreted relative to the current directory and may ascend to
// parent directories. If the provided name is constructed from user
// input, it should be sanitized before calling [ServeFile].
// If the provided name is constructed from user input, it should be
// sanitized before calling [ServeFileFS].
//
// As a precaution, ServeFile will reject requests where r.URL.Path
// As a precaution, ServeFileFS will reject requests where r.URL.Path
// contains a ".." path element; this protects against callers who
// might unsafely use [filepath.Join] on r.URL.Path without sanitizing
// it and then use that filepath.Join result as the name argument.
//
// As another special case, ServeFile redirects any request where r.URL.Path
// As another special case, ServeFileFS 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.
// use [ServeContent].
//
// Outside of those two special cases, ServeFile does not use
// Outside of those two special cases, ServeFileFS does not use
// r.URL.Path for selecting the file or directory to serve; only the
// file or directory provided in the name argument is used.
func ServeFileFS(w ResponseWriter, r *Request, fsys fs.FS, name string) {