gziphandler icon indicating copy to clipboard operation
gziphandler copied to clipboard

missing io.ReaderFrom for http1.1

Open romainmenke opened this issue 8 years ago • 1 comments
trafficstars

  • 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?

romainmenke avatar Mar 13 '17 20:03 romainmenke

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.

tmthrgd avatar May 28 '17 08:05 tmthrgd