net/http: using io.Copy to copy a file to http.ResponseWriter does not use sendfile #69097
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Go version
go version go1.22.6 linux/amd64
Output of
go env
in your module/workspace:What did you do?
Implement a Handler for http.Server and try to streaming a file:
What did you see happen?
io.Copy
not usingsendfile()
when copy from*os.File
tohttp.ResponseWriter
:io.Copy
first try to useWriterTo
from*os.File
, but*http.response
does not implement syscall.Conn interface;genericWriteTo
inWriteTo
of*os.File
;os.fileWithoutWriteTo
(file.go:269)io.Copy
try to use*http.response.ReadFrom()
which callssendfile()
TCPConn.ReadFrom()
*os.File
but aos.fileWithoutWriteTo
wrapper. (sendfile_linux_go:20)genericReadFrom()
which will do all the copying stuff (tcpsock_posix.go:54)What did you expect to see?
calling
sendfile()
in either*os.File.WriteTo
Or*http.response.ReadFrom
;The text was updated successfully, but these errors were encountered: