Skip to content

Commit

Permalink
net/http: mention io.Seeker requirement in FS documentation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thatoddmailbox committed Oct 4, 2021
1 parent 2dc91a2 commit 319a4d9
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/net/http/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,8 @@ 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
// for full compatibility with FileServer and NewFileTransport.
func FS(fsys fs.FS) FileSystem {
return ioFS{fsys}
}
Expand Down

0 comments on commit 319a4d9

Please sign in to comment.