aboutsummaryrefslogtreecommitdiff
path: root/http.go
diff options
context:
space:
mode:
Diffstat (limited to 'http.go')
-rw-r--r--http.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/http.go b/http.go
index 4f8718c..3b5747c 100644
--- a/http.go
+++ b/http.go
@@ -2104,10 +2104,19 @@ func limitedReaderSize(r io.Reader) int64 {
func writeBodyFixedSize(w *bufio.Writer, r io.Reader, size int64) error {
if size > maxSmallFileSize {
- // w buffer must be empty for triggering
- // sendfile path in bufio.Writer.ReadFrom.
- if err := w.Flush(); err != nil {
- return err
+ earlyFlush := false
+ switch r := r.(type) {
+ case *os.File:
+ earlyFlush = true
+ case *io.LimitedReader:
+ _, earlyFlush = r.R.(*os.File)
+ }
+ if earlyFlush {
+ // w buffer must be empty for triggering
+ // sendfile path in bufio.Writer.ReadFrom.
+ if err := w.Flush(); err != nil {
+ return err
+ }
}
}