一些优化

This commit is contained in:
Yun
2024-03-23 13:50:25 +08:00
parent 83e815bd1f
commit 05b6be76a8
+23 -23
View File
@@ -166,29 +166,29 @@ func (c *Curlx) SendWithResponee(ctx context.Context, ps ...Param) Response {
return r
}
var body []byte
switch resp.Header.Get("Content-Encoding") {
case "gzip":
reader, err := gzip.NewReader(resp.Body)
if err != nil {
r.err = err
return r
}
for {
buf := make([]byte, 1024)
n, err := reader.Read(buf)
if err != nil && err != io.EOF {
panic(err)
}
if n == 0 {
break
}
// 读取n个字节
body = append(body, buf[:n]...)
// body = append(body, buf...)
}
default:
body, _ = io.ReadAll(resp.Body)
}
// switch resp.Header.Get("Content-Encoding") {
// case "gzip":
// reader, err := gzip.NewReader(resp.Body)
// if err != nil {
// r.err = err
// return r
// }
// for {
// buf := make([]byte, 1024)
// n, err := reader.Read(buf)
// if err != nil && err != io.EOF {
// panic(err)
// }
// if n == 0 {
// break
// }
// // 读取n个字节
// body = append(body, buf[:n]...)
// // body = append(body, buf...)
// }
// default:
body, _ = io.ReadAll(resp.Body)
// }
r.body = body
c.opts.Logger.Infof(ctx, "curlx.Send body:%s", string(body))
return r