丑陋的解压

This commit is contained in:
eson 2018-12-18 01:42:38 +08:00
parent e165b6a0a0
commit 75fc71ccb4

View File

@ -37,23 +37,30 @@ func FromHTTPResponse(resp *http.Response) (*Response, error) {
srcReader := bytes.NewReader(srcbuf) srcReader := bytes.NewReader(srcbuf)
r, err := gzip.NewReader(srcReader) r, err := gzip.NewReader(srcReader)
defer r.Close()
if err == nil { if err == nil {
defer r.Close()
buf, err := ioutil.ReadAll(r) buf, err := ioutil.ReadAll(r)
if err != nil { if err != nil {
panic(err) panic(err)
} }
content = string(buf) content = string(buf)
} else { } else {
if r != nil {
r.Close()
}
r, err := zlib.NewReader(srcReader) r, err := zlib.NewReader(srcReader)
defer r.Close()
if err == nil { if err == nil {
defer r.Close()
buf, err := ioutil.ReadAll(r) buf, err := ioutil.ReadAll(r)
if err != nil { if err != nil {
panic(err) panic(err)
} }
content = string(buf) content = string(buf)
} else { } else {
if r != nil {
r.Close()
}
content = string(srcbuf) content = string(srcbuf)
} }
} }