ReadFrom will try to use sendfile to copy from the reader to the response writer. It's only used if the response writer implements io.ReaderFrom and the data can't be compressed. It's based on the standard library HTTP/1.1 response writer implementation. https://github.com/golang/go/blob/f4e3ec3dbe3
(r io.Reader)
| 380 | // It's based on the standard library HTTP/1.1 response writer implementation. |
| 381 | // https://github.com/golang/go/blob/f4e3ec3dbe3b8e04a058d266adf8e048bab563f2/src/net/http/server.go#L586 |
| 382 | func (rw *responseWriter) ReadFrom(r io.Reader) (int64, error) { |
| 383 | rf, ok := rw.ResponseWriter.(io.ReaderFrom) |
| 384 | // sendfile can't be used anyway |
| 385 | if !ok { |
| 386 | // mask ReadFrom to avoid infinite recursion |
| 387 | return io.Copy(writerOnly{rw}, r) |
| 388 | } |
| 389 | |
| 390 | var ns int64 |
| 391 | // try to sniff the content type and determine if the response should be compressed |
| 392 | if !rw.wroteHeader && rw.config.MinLength > 0 { |
| 393 | var ( |
| 394 | err error |
| 395 | buf [sniffLen]byte |
| 396 | ) |
| 397 | // mask ReadFrom to let Write determine if the response should be compressed |
| 398 | ns, err = io.CopyBuffer(writerOnly{rw}, io.LimitReader(r, sniffLen), buf[:]) |
| 399 | if err != nil || ns < sniffLen { |
| 400 | return ns, err |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | // the response will be compressed, no sendfile support |
| 405 | if rw.w != nil { |
| 406 | nr, err := io.Copy(rw.w, r) |
| 407 | return nr + ns, err |
| 408 | } |
| 409 | nr, err := rf.ReadFrom(r) |
| 410 | return nr + ns, err |
| 411 | } |
| 412 | |
| 413 | // Close writes any remaining buffered response and |
| 414 | // deallocates any active resources. |
nothing calls this directly
no outgoing calls
no test coverage detected