diff --git a/response.go b/response.go index 4176b10..77477d3 100644 --- a/response.go +++ b/response.go @@ -33,23 +33,29 @@ func FromHTTPResponse(resp *http.Response) (*Response, error) { // resp.Body = ioutil.NopCloser(cbuf) - content := string(srcbuf) + content := "" srcReader := bytes.NewReader(srcbuf) - if r, err := gzip.NewReader(srcReader); err == nil { - defer r.Close() + r, err := gzip.NewReader(srcReader) + defer r.Close() + if err == nil { buf, err := ioutil.ReadAll(r) if err != nil { panic(err) } content = string(buf) - } else if r, err := zlib.NewReader(srcReader); err == nil { + } else { + r, err := zlib.NewReader(srcReader) defer r.Close() - buf, err := ioutil.ReadAll(r) - if err != nil { - panic(err) + if err == nil { + buf, err := ioutil.ReadAll(r) + if err != nil { + panic(err) + } + content = string(buf) + } else { + content = string(srcbuf) } - content = string(buf) } return &Response{DContent: content, GResponse: resp}, nil