forked from jhunt/go-s3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace.go
37 lines (32 loc) · 759 Bytes
/
trace.go
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
36
37
package s3
import (
"io"
"net/http"
"net/http/httputil"
fmt "github.com/jhunt/go-ansi"
)
func (c *Client) Trace(out io.Writer, yes, body bool) {
c.traceTo = out
c.trace = yes || body
c.traceBody = body
}
func (c *Client) traceRequest(r *http.Request) error {
if c.trace {
what, err := httputil.DumpRequest(r, c.traceBody)
if err != nil {
return err
}
fmt.Fprintf(c.traceTo, "---[ request ]-----------------------------------\n@C{%s}\n\n", what)
}
return nil
}
func (c *Client) traceResponse(r *http.Response) error {
if c.trace {
what, err := httputil.DumpResponse(r, c.traceBody)
if err != nil {
return err
}
fmt.Fprintf(c.traceTo, "---[ response ]----------------------------------\n@W{%s}\n\n", what)
}
return nil
}