Skip to content

Commit bb523c9

Browse files
callthingsoffthanm
authored andcommitted
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Damien Neil <[email protected]> Reviewed-by: Mauri de Souza Meneguzzo <[email protected]>
1 parent 8f618c1 commit bb523c9

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/net/http/fs.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ func localRedirect(w ResponseWriter, r *Request, newPath string) {
747747
// If the provided file or directory name is a relative path, it is
748748
// interpreted relative to the current directory and may ascend to
749749
// parent directories. If the provided name is constructed from user
750-
// input, it should be sanitized before calling ServeFile.
750+
// input, it should be sanitized before calling [ServeFile].
751751
//
752752
// As a precaution, ServeFile will reject requests where r.URL.Path
753753
// contains a ".." path element; this protects against callers who
@@ -779,22 +779,20 @@ func ServeFile(w ResponseWriter, r *Request, name string) {
779779
// ServeFileFS replies to the request with the contents
780780
// of the named file or directory from the file system fsys.
781781
//
782-
// If the provided file or directory name is a relative path, it is
783-
// interpreted relative to the current directory and may ascend to
784-
// parent directories. If the provided name is constructed from user
785-
// input, it should be sanitized before calling [ServeFile].
782+
// If the provided name is constructed from user input, it should be
783+
// sanitized before calling [ServeFileFS].
786784
//
787-
// As a precaution, ServeFile will reject requests where r.URL.Path
785+
// As a precaution, ServeFileFS will reject requests where r.URL.Path
788786
// contains a ".." path element; this protects against callers who
789787
// might unsafely use [filepath.Join] on r.URL.Path without sanitizing
790788
// it and then use that filepath.Join result as the name argument.
791789
//
792-
// As another special case, ServeFile redirects any request where r.URL.Path
790+
// As another special case, ServeFileFS redirects any request where r.URL.Path
793791
// ends in "/index.html" to the same path, without the final
794792
// "index.html". To avoid such redirects either modify the path or
795-
// use ServeContent.
793+
// use [ServeContent].
796794
//
797-
// Outside of those two special cases, ServeFile does not use
795+
// Outside of those two special cases, ServeFileFS does not use
798796
// r.URL.Path for selecting the file or directory to serve; only the
799797
// file or directory provided in the name argument is used.
800798
func ServeFileFS(w ResponseWriter, r *Request, fsys fs.FS, name string) {

0 commit comments

Comments
 (0)