Skip to content

Commit

Permalink
Merge pull request #197 from longshine/avoid-read-from-bytes-reader
Browse files Browse the repository at this point in the history
Avoid reading all from bytes.Reader when get request body
  • Loading branch information
manicminer authored May 9, 2024
2 parents 22668fb + 4b2663e commit 8db2bb6
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,12 @@ func getBodyReaderAndContentLength(rawBody interface{}) (ReaderFunc, int64, erro
// deal with it seeking so want it to match here instead of the
// io.ReadSeeker case.
case *bytes.Reader:
buf, err := ioutil.ReadAll(body)
if err != nil {
return nil, 0, err
}
snapshot := *body
bodyReader = func() (io.Reader, error) {
return bytes.NewReader(buf), nil
r := snapshot
return &r, nil
}
contentLength = int64(len(buf))
contentLength = int64(body.Len())

// Compat case
case io.ReadSeeker:
Expand Down

0 comments on commit 8db2bb6

Please sign in to comment.