Merge pull request #20 from dchusovitin/patch-1

Fixed panic on logging requests without body (GET)
This commit is contained in:
Aliaksandr Pliutau 2016-12-29 09:32:30 +07:00 committed by GitHub
commit 68c4637d96

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"))