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:

https://github.com/golang/go/blob/2073b35e07ce9cea47ee1fbe763b304d2371954f/src/net/http/fs.go#L248-L252

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 https://github.com/golang/go/issues/44553 is similar, but unlike the current issue, it identifies it as a problem in the serveContent and suggests changing it.

Comment From: cherrymui

cc @neild

Comment From: gopherbot

Change https://go.dev/cl/597977 mentions this issue: net/http: document io.Seeker requirement for fs.FS arguments