Consume gzip stream in test

Also close writer since this test previously failed due to truncated
output.
This commit is contained in:
Andrew Gaul 2017-01-18 19:29:35 -08:00
parent f8cb20ade6
commit ecfa095a14
2 changed files with 6 additions and 2 deletions

View file

@ -5,6 +5,7 @@ import (
gzipp "compress/gzip"
jpegp "image/jpeg"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
@ -83,7 +84,10 @@ func (s *CompyTest) TestGzip(c *C) {
c.Assert(resp.StatusCode, Equals, 200)
c.Assert(resp.Header.Get("Content-Encoding"), Equals, "gzip")
_, err = gzipp.NewReader(resp.Body)
gzr, err := gzipp.NewReader(resp.Body)
c.Assert(err, IsNil)
defer gzr.Close()
_, err = ioutil.ReadAll(gzr)
c.Assert(err, IsNil)
}

View file

@ -38,7 +38,7 @@ func (t *Gzip) Transcode(w *proxy.ResponseWriter, r *proxy.ResponseReader, heade
if err != nil {
return err
}
defer gzw.Flush()
defer gzw.Close()
w.Writer = gzw
w.Header().Set("Content-Encoding", "gzip")
}