commit | 5f5a55679c54784d07643099b55228b6f88c0bdf | [log] [tgz] |
---|---|---|
author | Paul Forgey <paulf@tessier-ashpool.net> | Tue Sep 01 00:38:01 2020 +0000 |
committer | Emmanuel Odeke <emm.odeke@gmail.com> | Tue Sep 01 00:55:12 2020 +0000 |
tree | ba046f20b0e1a0ebea5e4a592f31ae0ec4d81f95 | |
parent | e01a226fadcac721e26c12921ca54388c7244d03 [diff] |
net/http: refactor ResponseWriter.ReadFrom to permit splice on Linux Rather than probe and guess if sendfile will work inside ResponseWriter.ReadFrom(src), this change fixes the underlying issue of starting to respond before src is readable We'll no longer send a status OK if a header has not yet been written and reading from src is destined to fail. This small change implicitly takes care of the need for the server to sniff the response body to determine the Content-Type. This allows splice to work on Linux when src is a socket or any non-regular file that's spliceable. The extra read of 512 bytes may raise an objection, and that's fair, but we're already swapping some syscall prep work for another and a read of 512 probably will not impact the overall performance. For shorter bodies, there's likely less setup time. A little initial slop is not too unusual in zero copy network code, and sometimes actually helps. Fixes #40888 Change-Id: I4a8e2ad0ace1318bae66dae5671d06ea6d4838ed GitHub-Last-Rev: 097364ea866613d103a31e2247b44f4a12077f9e GitHub-Pull-Request: golang/go#40903 Reviewed-on: https://go-review.googlesource.com/c/go/+/249238 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Gopher image by Renee French, licensed under Creative Commons 3.0 Attributions license.
Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
Official binary distributions are available at https://golang.org/dl/.
After downloading a binary release, visit https://golang.org/doc/install or load doc/install.html in your web browser for installation instructions.
If a binary distribution is not available for your combination of operating system and architecture, visit https://golang.org/doc/install/source or load doc/install-source.html in your web browser for source installation instructions.
Go is the work of thousands of contributors. We appreciate your help!
To contribute, please read the contribution guidelines: https://golang.org/doc/contribute.html
Note that the Go project uses the issue tracker for bug reports and proposals only. See https://golang.org/wiki/Questions for a list of places to ask questions about the Go language.