server: http log sent bytes

This commit is contained in:
mmatczuk 2016-09-27 09:10:55 +02:00
parent 1bbcb98198
commit 7849170e92
2 changed files with 14 additions and 1 deletions

View file

@ -252,8 +252,10 @@ func (s *Server) proxy(host string, w io.Writer, r interface{}, msg *proto.Contr
localToRemote := func() {
if hr, ok := r.(*http.Request); ok {
hr.Write(pw)
cw := &countWriter{pw, 0}
hr.Write(cw)
pw.Close()
s.log.Debug("Coppied %d bytes from %s", cw.count, "local to remote")
} else {
transfer("local to remote", pw, r.(io.ReadCloser), s.log)
}

View file

@ -46,6 +46,17 @@ func copyHeader(dst, src http.Header) {
}
}
type countWriter struct {
w io.Writer
count int64
}
func (cw *countWriter) Write(p []byte) (n int, err error) {
n, err = cw.w.Write(p)
cw.count += int64(n)
return
}
type flushWriter struct {
w io.Writer
}