missing io.ReaderFrom for http1.1
romainmenke opened this issue · 1 comments
- Go 1.8 / 1.75 / 1.6.5
- osx / linux
Validation with https://middleware.vet#github.com/NYTimes/gziphandler shows that GzipResponseWriter
is not implementing io.ReaderFrom
for http1.1
Is it possible to implement these only for http1.1 and not for http2 while still reusing response writers?
The io.ReaderFrom is implemented by *net/http.response for HTTP 1.x connections. If the underlying connection is a TCPConn then it uses the optimised sendfile system call (see (*TCPConn).readFrom) which, according to the man page:
sendfile() copies data between one file descriptor and another. Because this copying is done within the kernel, sendfile() is more efficient than the combination of read(2) and write(2), which would require transferring data to and from user space.
Unfortunately this optimisation is not possible because gziphandler has to gzip the response body. There is just no straight path from file descriptor to file descriptor.