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

Commit

Permalink
Allow empty body
Browse files Browse the repository at this point in the history
  • Loading branch information
borchero committed Jun 21, 2023
1 parent 7fd8d1c commit 4c2b54f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,18 @@ func (c *Client) newRequest(method, requestPath string, query url.Values, body i
log.Printf("request (%s) to %s with no body data", method, url.String())
} else {
reader := body.(*bytes.Reader)
contents := make([]byte, reader.Len())
if _, err := reader.Read(contents); err != nil {
return nil, fmt.Errorf("cannot read body contents for logging: %w", err)
if reader.Len() == 0 {
log.Printf("request (%s) to %s with no body data", method, url.String())
} else {
contents := make([]byte, reader.Len())
if _, err := reader.Read(contents); err != nil {
return nil, fmt.Errorf("cannot read body contents for logging: %w", err)
}
if _, err := reader.Seek(0, io.SeekStart); err != nil {
return nil, fmt.Errorf("failed to seek body reader to start after logging: %w", err)
}
log.Printf("request (%s) to %s with body data: %s", method, url.String(), string(contents))
}
if _, err := reader.Seek(0, io.SeekStart); err != nil {
return nil, fmt.Errorf("failed to seek body reader to start after logging: %w", err)
}
log.Printf("request (%s) to %s with body data: %s", method, url.String(), string(contents))
}
}

Expand Down

0 comments on commit 4c2b54f

Please sign in to comment.