net/http: mention io.Seeker requirement in FS documentation

Both FileServer and NewFileTransport can try to seek a file, specifically
when MIME type sniffing is performed. This can be somewhat surprising to an
implementer of an fs.FS, as their filesystem will appear to work until a
user tries to access a file with an unrecognized extension (which requires
type sniffing and therefore seeking). With FileServer, this results in a
"seeker can't seek" message, which is not very clear for the developer.

The issue arises because fs.FS does not require Seek, while http.FileSystem
does. Therefore, this change adds a line to the documentation of net/http's
adapter function mentioning the requirement.
This commit is contained in:
Alex Studer 2021-10-04 17:31:44 -04:00
parent 4e565f7372
commit fddccdae36
No known key found for this signature in database
GPG Key ID: 03906C0E0E1E6707
1 changed files with 1 additions and 0 deletions

View File

@ -815,6 +815,7 @@ func (f ioFile) Readdir(count int) ([]fs.FileInfo, error) {
// FS converts fsys to a FileSystem implementation,
// for use with FileServer and NewFileTransport.
// The files provided by fsys must implement io.Seeker.
func FS(fsys fs.FS) FileSystem {
return ioFS{fsys}
}