Skip to content

Commit

Permalink
Return partial body. (#239)
Browse files Browse the repository at this point in the history
If there's an error reading the response but we got some data, set it so the caller can read it.

This is needed to work around a bug in Percipio's API. If the response is large enough, it returns an incorrect content length and closes the connection unexpectedly. The response contains the full JSON payload... most of the time.
  • Loading branch information
ggreer authored Oct 8, 2024
1 parent 28ff0cb commit d5cd62f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/uhttp/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,10 @@ func (c *BaseHttpClient) Do(req *http.Request, options ...DoOption) (*http.Respo
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
if len(body) > 0 {
resp.Body = io.NopCloser(bytes.NewBuffer(body))
}
return resp, err
}

// Replace resp.Body with a no-op closer so nobody has to worry about closing the reader.
Expand Down

0 comments on commit d5cd62f

Please sign in to comment.