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.
This commit is contained in:
parent
582f0cf0e3
commit
0f923d7926
|
@ -124,11 +124,16 @@ func (f *fancyWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||||
|
|
||||||
func (f *fancyWriter) ReadFrom(r io.Reader) (int64, error) {
|
func (f *fancyWriter) ReadFrom(r io.Reader) (int64, error) {
|
||||||
if f.basicWriter.tee != nil {
|
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)
|
rf := f.basicWriter.ResponseWriter.(io.ReaderFrom)
|
||||||
f.basicWriter.maybeWriteHeader()
|
f.basicWriter.maybeWriteHeader()
|
||||||
return rf.ReadFrom(r)
|
|
||||||
|
n, err := rf.ReadFrom(r)
|
||||||
|
f.bytes += int(n)
|
||||||
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
type flushWriter struct {
|
type flushWriter struct {
|
||||||
|
|
Loading…
Reference in New Issue