Skip to content

Commit

Permalink
revert: pr #541 because it breaks the io.Reader bufferless processing
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Sep 17, 2023
1 parent 15cedd4 commit cd394d0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ CL:

func createHTTPRequest(c *Client, r *Request) (err error) {
if r.bodyBuf == nil {
if c.setContentLength || r.setContentLength {
if reader, ok := r.Body.(io.Reader); ok {
r.RawRequest, err = http.NewRequest(r.Method, r.URL, reader)
} else if c.setContentLength || r.setContentLength {
r.RawRequest, err = http.NewRequest(r.Method, r.URL, http.NoBody)
} else {
r.RawRequest, err = http.NewRequest(r.Method, r.URL, nil)
Expand Down Expand Up @@ -441,9 +443,14 @@ func handleRequestBody(c *Client, r *Request) (err error) {
r.bodyBuf = nil

if reader, ok := r.Body.(io.Reader); ok {
r.bodyBuf = acquireBuffer()
_, err = r.bodyBuf.ReadFrom(reader)
r.Body = nil
if c.setContentLength || r.setContentLength { // keep backward compatibility
r.bodyBuf = acquireBuffer()
_, err = r.bodyBuf.ReadFrom(reader)
r.Body = nil
} else {
// Otherwise buffer less processing for `io.Reader`, sounds good.
return
}
} else if b, ok := r.Body.([]byte); ok {
bodyBytes = b
} else if s, ok := r.Body.(string); ok {
Expand Down

0 comments on commit cd394d0

Please sign in to comment.