Skip to content

net/http: document that the fs.FS passed to ServeFileFS, FileServerFS, and NewFileTransportFS must implement io.Seeker #66877

Closed
@gazerro

Description

@gazerro

The fs.FS argument, passed to the functions http.ServeFileFS, http.FileServerFS, and http.NewFileTransportFS, must implement io.Seeker. However, this requirement is not documented in these functions.

If io.Seeker is not implemented, these functions may fail to serve files and instead could send a 500 error to the client. Here is the code from the serveContent function where the error is returned:

go/src/net/http/fs.go

Lines 248 to 252 in 2073b35

_, err := content.Seek(0, io.SeekStart) // rewind to output whole file
if err != nil {
Error(w, "seeker can't seek", StatusInternalServerError)
return
}

This error can be tricky to detect as it only appears if the "Content-Type" header of the response hasn’t been set earlier.

Note that the issue #44553 is similar, but unlike the current issue, it identifies it as a problem in the serveContent and suggests changing it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.help wanted

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions