Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gazerro opened this issue Apr 17, 2024 · 1 comment
Labels
Documentation help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@gazerro
Copy link
Contributor

gazerro commented Apr 17, 2024

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.

@seankhliao seankhliao changed the title http: document that the fs.FS passed to ServeFileFS, FileServerFS, and NewFileTransportFS must implement io.Seeker net/http: document that the fs.FS passed to ServeFileFS, FileServerFS, and NewFileTransportFS must implement io.Seeker Apr 17, 2024
@cherrymui cherrymui added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 18, 2024
@cherrymui cherrymui added this to the Backlog milestone Apr 18, 2024
@cherrymui
Copy link
Member

cc @neild

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants