Skip to content

Commit

Permalink
处理fasthttp 返回http body 问题
Browse files Browse the repository at this point in the history
  • Loading branch information
wzhsh90 committed Jul 16, 2024
1 parent 48b250e commit 23d241f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions common/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func Get(url string, headers map[string]string) (respDa []byte, err error) {
}
body := resp.Body()
if body != nil {
return body, nil
//这里只能返回复制,不然有隐藏bug
return bytes.Clone(body), nil
} else {
return nil, errors.New("empty")
}
Expand Down Expand Up @@ -61,7 +62,8 @@ func PostXml(path string, xmlString string, tlsConfig *tls.Config, timeout time.
}
body := resp.Body()
if body != nil {
return body, nil
//这里只能返回复制,不然有隐藏bug
return bytes.Clone(body), nil
} else {
return nil, errors.New("empty")
}
Expand Down Expand Up @@ -105,7 +107,8 @@ func PostFile(url string, data map[string]string, headers map[string]string, nam
}
body := resp.Body()
if body != nil {
return body, nil
//这里只能返回复制,不然有隐藏bug
return bytes.Clone(body), nil
} else {
return nil, errors.New("empty")
}
Expand Down Expand Up @@ -133,7 +136,8 @@ func PostJson(path string, jsonData string, headers map[string]string) ([]byte,
}
body := resp.Body()
if body != nil {
return body, nil
//这里只能返回复制,不然有隐藏bug
return bytes.Clone(body), nil
} else {
return nil, errors.New("empty")
}
Expand Down Expand Up @@ -165,7 +169,8 @@ func PostForm(url string, data map[string]string, headers map[string]string) (re
}
body := resp.Body()
if body != nil {
return body, nil
//这里只能返回复制,不然有隐藏bug
return bytes.Clone(body), nil
} else {
return nil, errors.New("empty")
}
Expand Down

0 comments on commit 23d241f

Please sign in to comment.