一些优化
This commit is contained in:
@@ -166,29 +166,29 @@ func (c *Curlx) SendWithResponee(ctx context.Context, ps ...Param) Response {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
var body []byte
|
var body []byte
|
||||||
switch resp.Header.Get("Content-Encoding") {
|
// switch resp.Header.Get("Content-Encoding") {
|
||||||
case "gzip":
|
// case "gzip":
|
||||||
reader, err := gzip.NewReader(resp.Body)
|
// reader, err := gzip.NewReader(resp.Body)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
r.err = err
|
// r.err = err
|
||||||
return r
|
// return r
|
||||||
}
|
// }
|
||||||
for {
|
// for {
|
||||||
buf := make([]byte, 1024)
|
// buf := make([]byte, 1024)
|
||||||
n, err := reader.Read(buf)
|
// n, err := reader.Read(buf)
|
||||||
if err != nil && err != io.EOF {
|
// if err != nil && err != io.EOF {
|
||||||
panic(err)
|
// panic(err)
|
||||||
}
|
// }
|
||||||
if n == 0 {
|
// if n == 0 {
|
||||||
break
|
// break
|
||||||
}
|
// }
|
||||||
// 读取n个字节
|
// // 读取n个字节
|
||||||
body = append(body, buf[:n]...)
|
// body = append(body, buf[:n]...)
|
||||||
// body = append(body, buf...)
|
// // body = append(body, buf...)
|
||||||
}
|
// }
|
||||||
default:
|
// default:
|
||||||
body, _ = io.ReadAll(resp.Body)
|
body, _ = io.ReadAll(resp.Body)
|
||||||
}
|
// }
|
||||||
r.body = body
|
r.body = body
|
||||||
c.opts.Logger.Infof(ctx, "curlx.Send body:%s", string(body))
|
c.opts.Logger.Infof(ctx, "curlx.Send body:%s", string(body))
|
||||||
return r
|
return r
|
||||||
|
|||||||
Reference in New Issue
Block a user