mirror of
https://gitee.com/johng/gf.git
synced 2024-11-30 11:18:02 +08:00
fix issue of nil response handling for ghttp.Client
This commit is contained in:
parent
8368e11827
commit
ce40d139e7
1
go.mod
1
go.mod
@ -10,6 +10,7 @@ require (
|
||||
github.com/gomodule/redigo v2.0.0+incompatible
|
||||
github.com/gorilla/websocket v1.4.1
|
||||
github.com/grokify/html-strip-tags-go v0.0.0-20190921062105-daaa06bf1aaf
|
||||
github.com/mattn/go-runewidth v0.0.10 // indirect
|
||||
github.com/olekukonko/tablewriter v0.0.1
|
||||
go.opentelemetry.io/otel v0.16.0
|
||||
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102
|
||||
|
@ -58,7 +58,7 @@ func (r *Response) RawRequest() string {
|
||||
|
||||
// RawResponse returns the raw content of the response.
|
||||
func (r *Response) RawResponse() string {
|
||||
// Response can be nil.
|
||||
// Response might be nil.
|
||||
if r == nil || r.Response == nil {
|
||||
return ""
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ func (c *Client) DoRequest(method, url string, data ...interface{}) (resp *Respo
|
||||
}
|
||||
|
||||
// Auto saving cookie content.
|
||||
if c.browserMode && resp != nil {
|
||||
if c.browserMode && resp != nil && resp.Response != nil {
|
||||
now := time.Now()
|
||||
for _, v := range resp.Response.Cookies() {
|
||||
if !v.Expires.IsZero() && v.Expires.UnixNano() < now.UnixNano() {
|
||||
|
@ -49,6 +49,10 @@ func (r *Response) GetCookieMap() map[string]string {
|
||||
|
||||
// ReadAll retrieves and returns the response content as []byte.
|
||||
func (r *Response) ReadAll() []byte {
|
||||
// Response might be nil.
|
||||
if r == nil || r.Response == nil {
|
||||
return []byte{}
|
||||
}
|
||||
body, err := ioutil.ReadAll(r.Response.Body)
|
||||
if err != nil {
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user