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

missing io.ReaderFrom for http1.1 #35

Open
romainmenke opened this issue Mar 13, 2017 · 1 comment
Open

missing io.ReaderFrom for http1.1 #35

romainmenke opened this issue Mar 13, 2017 · 1 comment

Comments

@romainmenke
Copy link
Contributor

romainmenke commented Mar 13, 2017

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

@tmthrgd
Copy link
Contributor

tmthrgd commented May 28, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants