Skip to content

Commit

Permalink
Fix: mutil.fancyWriter.ReadFrom records number of bytes written (#256)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jackc committed Apr 22, 2021
1 parent 582f0cf commit 0f923d7
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions hlog/internal/mutil/writer_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0f923d7

Please sign in to comment.