Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Commit 7fd8d1c

Browse files
committed
Fix logging when setting GF_LOG=1
1 parent 023cfdf commit 7fd8d1c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

client.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,15 @@ func (c *Client) newRequest(method, requestPath string, query url.Values, body i
181181
if body == nil {
182182
log.Printf("request (%s) to %s with no body data", method, url.String())
183183
} else {
184-
log.Printf("request (%s) to %s with body data: %s", method, url.String(), body.(*bytes.Buffer).String())
184+
reader := body.(*bytes.Reader)
185+
contents := make([]byte, reader.Len())
186+
if _, err := reader.Read(contents); err != nil {
187+
return nil, fmt.Errorf("cannot read body contents for logging: %w", err)
188+
}
189+
if _, err := reader.Seek(0, io.SeekStart); err != nil {
190+
return nil, fmt.Errorf("failed to seek body reader to start after logging: %w", err)
191+
}
192+
log.Printf("request (%s) to %s with body data: %s", method, url.String(), string(contents))
185193
}
186194
}
187195

0 commit comments

Comments
 (0)