diff options
author | WeidiDeng <[email protected]> | 2024-09-07 19:47:32 +0800 |
---|---|---|
committer | GitHub <[email protected]> | 2024-09-07 19:47:32 +0800 |
commit | c8cdb9f7d22b5bd733a539ad741ba4502fbda731 (patch) | |
tree | 489d3837b5270503e74d338b0d1368aa86c4c9da | |
parent | 91e62db666b799ba4bb6577d8548fbe779d91c28 (diff) | |
download | caddy-c8cdb9f7d22b5bd733a539ad741ba4502fbda731.tar.gz caddy-c8cdb9f7d22b5bd733a539ad741ba4502fbda731.zip |
http: ReponseWriter prefer ReadFrom if availableresponsewriter-readfrom
-rw-r--r-- | modules/caddyhttp/responsewriter.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/modules/caddyhttp/responsewriter.go b/modules/caddyhttp/responsewriter.go index 808d2de3a..3c0f89d0b 100644 --- a/modules/caddyhttp/responsewriter.go +++ b/modules/caddyhttp/responsewriter.go @@ -42,9 +42,13 @@ func (rww *ResponseWriterWrapper) Push(target string, opts *http.PushOptions) er return ErrNotImplemented } -// ReadFrom implements io.ReaderFrom. It simply calls io.Copy, -// which uses io.ReaderFrom if available. +// ReadFrom implements io.ReaderFrom. It retries to use io.ReaderFrom if available, +// then fallback to io.Copy. +// see: https://github.com/caddyserver/caddy/issues/6546 func (rww *ResponseWriterWrapper) ReadFrom(r io.Reader) (n int64, err error) { + if rf, ok := rww.ResponseWriter.(io.ReaderFrom); ok { + return rf.ReadFrom(r) + } return io.Copy(rww.ResponseWriter, r) } |