Skip to content

Commit

Permalink
Bugfix: fix mishandling of POST requests with no body, causing net/ht…
Browse files Browse the repository at this point in the history
…tp to send request without a Content-Length
  • Loading branch information
manicminer committed May 5, 2023
1 parent 2bcd5fe commit 7bf089a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,17 @@ func getBodyReaderAndContentLength(rawBody interface{}) (ReaderFunc, int64, erro
if err != nil {
return nil, 0, err
}
bodyReader = func() (io.Reader, error) {
return bytes.NewReader(buf), nil
if len(buf) == 0 {
bodyReader = func() (io.Reader, error) {
return http.NoBody, nil
}
contentLength = 0
} else {
bodyReader = func() (io.Reader, error) {
return bytes.NewReader(buf), nil
}
contentLength = int64(len(buf))
}
contentLength = int64(len(buf))

// No body provided, nothing to do
case nil:
Expand Down

0 comments on commit 7bf089a

Please sign in to comment.