优化body读取的逻辑, 0byte的body将会自动跳过读取

This commit is contained in:
M09Ic 2023-01-10 11:59:43 +08:00
parent 33da70c457
commit 0b8fed7e80
2 changed files with 10 additions and 7 deletions

View File

@ -294,7 +294,6 @@ func (pool *Pool) Invoke(v interface{}) {
return return
} }
req.SetHeaders(pool.Headers) req.SetHeaders(pool.Headers)
start := time.Now() start := time.Now()
resp, reqerr := pool.client.Do(pool.ctx, req) resp, reqerr := pool.client.Do(pool.ctx, req)
if pool.ClientType == ihttp.FAST { if pool.ClientType == ihttp.FAST {

View File

@ -33,12 +33,16 @@ func NewBaseline(u, host string, resp *ihttp.Response) *Baseline {
copy(bl.Header, header) copy(bl.Header, header)
bl.HeaderLength = len(bl.Header) bl.HeaderLength = len(bl.Header)
if i := resp.ContentLength(); i != 0 {
body := resp.Body() body := resp.Body()
bl.Body = make([]byte, len(body)) bl.Body = make([]byte, len(body))
copy(bl.Body, body) copy(bl.Body, body)
bl.BodyLength = resp.ContentLength()
if bl.BodyLength == -1 { if i == -1 {
bl.BodyLength = len(bl.Body) bl.BodyLength = len(bl.Body)
} else {
bl.BodyLength = i
}
} }
if t, ok := ContentTypeMap[resp.ContentType()]; ok { if t, ok := ContentTypeMap[resp.ContentType()]; ok {