Skip to content

Commit

Permalink
http: do not use buffer when draining and discarding http body
Browse files Browse the repository at this point in the history
Use io.Copy with io.Discard instead of io.ReadAll to drain the whole http body
when an error occurred.

This does not write the body unnecessary to a buffer in memory that will never
be used.
  • Loading branch information
fho committed Dec 12, 2023
1 parent 00a0f52 commit eacc475
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion internal/jenkins/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (c *Client) do(method, url string, result interface{}) error {
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
_, _ = io.ReadAll(resp.Body)
_, _ = io.Copy(io.Discard, resp.Body)
return &ErrHTTPRequestFailed{Code: resp.StatusCode}
}

Expand Down

0 comments on commit eacc475

Please sign in to comment.