fix: allow ResponseReader.Reader to be wrapped by transcoders

fixes -minify errors
This commit is contained in:
Barna Csorogi 2017-01-14 03:44:07 +01:00
parent 1d5b6eff72
commit 480053a71a
2 changed files with 8 additions and 5 deletions

View file

@ -69,7 +69,7 @@ func (p *Proxy) handle(w http.ResponseWriter, r *http.Request) error {
rw := newResponseWriter(w) rw := newResponseWriter(w)
rr := newResponseReader(resp) rr := newResponseReader(resp)
err = p.proxyResponse(rw, rr) err = p.proxyResponse(rw, rr)
read := rr.Count() read := rr.counter.Count()
written := rw.rw.Count() written := rw.rw.Count()
log.Printf("transcoded: %d -> %d (%3.1f%%)", read, written, float64(written)/float64(read)*100) log.Printf("transcoded: %d -> %d (%3.1f%%)", read, written, float64(written)/float64(read)*100)
atomic.AddUint64(&p.ReadCount, read) atomic.AddUint64(&p.ReadCount, read)

View file

@ -9,14 +9,17 @@ import (
) )
type ResponseReader struct { type ResponseReader struct {
datacounter.ReaderCounter io.Reader
r *http.Response counter *datacounter.ReaderCounter
r *http.Response
} }
func newResponseReader(r *http.Response) *ResponseReader { func newResponseReader(r *http.Response) *ResponseReader {
counter := datacounter.NewReaderCounter(r.Body)
return &ResponseReader{ return &ResponseReader{
ReaderCounter: *datacounter.NewReaderCounter(r.Body), Reader: counter,
r: r, counter: counter,
r: r,
} }
} }