forked from parnurzeal/gorequest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.go
More file actions
35 lines (31 loc) · 767 Bytes
/
Copy pathdebug.go
File metadata and controls
35 lines (31 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package gorequest
import (
"net/http"
"net/http/httputil"
)
// SetDebug enable the debug mode which logs request/response detail.
func (s *SuperAgent) SetDebug(enable bool) *SuperAgent {
s.Debug = enable
return s
}
func (s *SuperAgent) debuggingRequest(req *http.Request) {
if s.Debug {
dump, err := httputil.DumpRequest(req, true)
s.logger.SetPrefix("[http] ")
if err != nil {
s.logger.Println("Error:", err)
} else {
s.logger.Printf("HTTP Request: %s", BytesToString(dump))
}
}
}
func (s *SuperAgent) debuggingResponse(resp *http.Response) {
if s.Debug {
dump, err := httputil.DumpResponse(resp, true)
if nil != err {
s.logger.Println("Error:", err)
} else {
s.logger.Printf("HTTP Response: %s", BytesToString(dump))
}
}
}