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" gzipp "compress/gzip"
jpegp "image/jpeg" jpegp "image/jpeg"
"io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
@ -83,7 +84,10 @@ func (s *CompyTest) TestGzip(c *C) {
c.Assert(resp.StatusCode, Equals, 200) c.Assert(resp.StatusCode, Equals, 200)
c.Assert(resp.Header.Get("Content-Encoding"), Equals, "gzip") 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) c.Assert(err, IsNil)
} }

View file

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