Skip to content

Commit

Permalink
Don't unwrap io.LimitedReader
Browse files Browse the repository at this point in the history
This is not needed anymore to trigger sendfile. The Go wrapper around
sendfile already does this: https://github.com/golang/go/blob/9d46ee5ac4acd6602692f70c5149a3f6db058558/src/net/sendfile_linux.go#L23-L33
  • Loading branch information
erikdubbelboer committed Jun 12, 2021
1 parent 6233fbc commit b8b065b
Showing 1 changed file with 0 additions and 11 deletions.
11 changes: 0 additions & 11 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -1856,19 +1856,8 @@ func writeBodyFixedSize(w *bufio.Writer, r io.Reader, size int64) error {
}
}

// Unwrap a single limited reader for triggering sendfile path
// in net.TCPConn.ReadFrom.
lr, ok := r.(*io.LimitedReader)
if ok {
r = lr.R
}

n, err := copyZeroAlloc(w, r)

if ok {
lr.N -= n
}

if n != size && err == nil {
err = fmt.Errorf("copied %d bytes from body stream instead of %d bytes", n, size)
}
Expand Down

0 comments on commit b8b065b

Please sign in to comment.