@@ -97,13 +97,23 @@ func (c *Client) Send(req *http.Request, v interface{}) error {
97
97
if c .returnRepresentation {
98
98
req .Header .Set ("Prefer" , "return=representation" )
99
99
}
100
+ if c .Log != nil {
101
+ if reqDump , err := httputil .DumpRequestOut (req , true ); err == nil {
102
+ c .Log .Write ([]byte (fmt .Sprintf ("Request: %s\n " , reqDump )))
103
+ }
104
+ }
100
105
101
106
resp , err = c .Client .Do (req )
102
- c .log (req , resp )
103
-
104
107
if err != nil {
105
108
return err
106
109
}
110
+
111
+ if c .Log != nil {
112
+ if respDump , err := httputil .DumpResponse (resp , true ); err == nil {
113
+ c .Log .Write ([]byte (fmt .Sprintf ("Response from %s: %s\n " , req .URL , respDump )))
114
+ }
115
+ }
116
+
107
117
defer func (Body io.ReadCloser ) error {
108
118
return Body .Close ()
109
119
}(resp .Body )
@@ -180,22 +190,3 @@ func (c *Client) NewRequest(ctx context.Context, method, url string, payload int
180
190
}
181
191
return http .NewRequestWithContext (ctx , method , url , buf )
182
192
}
183
-
184
- // log will dump request and response to the log file
185
- func (c * Client ) log (r * http.Request , resp * http.Response ) {
186
- if c .Log != nil {
187
- var (
188
- reqDump string
189
- respDump []byte
190
- )
191
-
192
- if r != nil {
193
- reqDump = fmt .Sprintf ("%s %s. Data: %s" , r .Method , r .URL .String (), r .Form .Encode ())
194
- }
195
- if resp != nil {
196
- respDump , _ = httputil .DumpResponse (resp , true )
197
- }
198
-
199
- c .Log .Write ([]byte (fmt .Sprintf ("Request: %s\n Response: %s\n " , reqDump , string (respDump ))))
200
- }
201
- }
0 commit comments