From bf0e0883a88973177808d4ad8b706893beccb6fc Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 5 Oct 2021 13:16:14 +0800 Subject: [PATCH] Fix debug (#545) As title. Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/545 Reviewed-by: Norwin Reviewed-by: techknowlogick Co-authored-by: Lunny Xiao Co-committed-by: Lunny Xiao --- gitea/client.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gitea/client.go b/gitea/client.go index 9f857f8..30204ef 100644 --- a/gitea/client.go +++ b/gitea/client.go @@ -6,6 +6,7 @@ package gitea import ( + "bytes" "context" "encoding/json" "errors" @@ -192,7 +193,13 @@ func (c *Client) doRequest(method, path string, header http.Header, body io.Read c.mutex.RLock() debug := c.debug if debug { - fmt.Printf("%s: %s\nHeader: %v\nBody: %s\n", method, c.url+"/api/v1"+path, header, body) + var bodyStr string + if body != nil { + bs, _ := ioutil.ReadAll(body) + body = bytes.NewReader(bs) + bodyStr = string(bs) + } + fmt.Printf("%s: %s\nHeader: %v\nBody: %s\n", method, c.url+"/api/v1"+path, header, bodyStr) } req, err := http.NewRequestWithContext(c.ctx, method, c.url+"/api/v1"+path, body) if err != nil {