Open romainmenke opened 7 years ago
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.
Validation with https://middleware.vet#github.com/NYTimes/gziphandler shows that
GzipResponseWriter
is not implementingio.ReaderFrom
for http1.1Is it possible to implement these only for http1.1 and not for http2 while still reusing response writers?