diff --git a/response.go b/response.go index 77477d3..bf7acdd 100644 --- a/response.go +++ b/response.go @@ -37,23 +37,30 @@ func FromHTTPResponse(resp *http.Response) (*Response, error) { srcReader := bytes.NewReader(srcbuf) r, err := gzip.NewReader(srcReader) - defer r.Close() if err == nil { + defer r.Close() buf, err := ioutil.ReadAll(r) if err != nil { panic(err) } content = string(buf) } else { + if r != nil { + r.Close() + } + r, err := zlib.NewReader(srcReader) - defer r.Close() if err == nil { + defer r.Close() buf, err := ioutil.ReadAll(r) if err != nil { panic(err) } content = string(buf) } else { + if r != nil { + r.Close() + } content = string(srcbuf) } }