From 0f923d79268f95ae2d4a5c173430c6480fa5121e Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Wed, 21 Apr 2021 20:22:35 -0500 Subject: [PATCH] Fix: mutil.fancyWriter.ReadFrom records number of bytes written (#256) Without this hlog.AccessHnalder reports a size written of 0 when the ReadFrom method is used. This is easily visible when using http.FileServer where all files are served with a logged size of 0. --- hlog/internal/mutil/writer_proxy.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hlog/internal/mutil/writer_proxy.go b/hlog/internal/mutil/writer_proxy.go index 598a86f..9d42739 100644 --- a/hlog/internal/mutil/writer_proxy.go +++ b/hlog/internal/mutil/writer_proxy.go @@ -124,11 +124,16 @@ func (f *fancyWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { func (f *fancyWriter) ReadFrom(r io.Reader) (int64, error) { if f.basicWriter.tee != nil { - return io.Copy(&f.basicWriter, r) + n, err := io.Copy(&f.basicWriter, r) + f.bytes += int(n) + return n, err } rf := f.basicWriter.ResponseWriter.(io.ReaderFrom) f.basicWriter.maybeWriteHeader() - return rf.ReadFrom(r) + + n, err := rf.ReadFrom(r) + f.bytes += int(n) + return n, err } type flushWriter struct {