Fixed panic on logging requests without body (GET)

This commit is contained in:
Dmitry Chusovitin 2016-12-28 20:48:50 +03:00 committed by GitHub
parent 72454421ef
commit be08e9ec4a

View File

@ -135,8 +135,6 @@ func (c *Client) NewRequest(method, url string, payload interface{}) (*http.Requ
func (c *Client) log(r *http.Request, resp *http.Response) { func (c *Client) log(r *http.Request, resp *http.Response) {
if c.Log != nil { if c.Log != nil {
reqDump := fmt.Sprintf("%s %s. Data: %s", r.Method, r.URL.String(), r.Form.Encode()) reqDump := fmt.Sprintf("%s %s. Data: %s", r.Method, r.URL.String(), r.Form.Encode())
dump, _ := ioutil.ReadAll(r.Body)
fmt.Println(string(dump))
respDump, _ := httputil.DumpResponse(resp, true) respDump, _ := httputil.DumpResponse(resp, true)
c.Log.Write([]byte("Request: " + reqDump + "\nResponse: " + string(respDump) + "\n\n")) c.Log.Write([]byte("Request: " + reqDump + "\nResponse: " + string(respDump) + "\n\n"))