Skip to content

Commit

Permalink
Remove the Body of PUT requests for 0-length files
Browse files Browse the repository at this point in the history
  • Loading branch information
moredatarequired committed Apr 6, 2024
1 parent 397584f commit 0999f7a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/internal/filetransfer/file_transfer_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ func (ft *DefaultFileTransfer) Upload(task *Task) error {
if err != nil {
return err
}
if task.Size == 0 {
// *Sometimes* on *some* platforms, req.Body is set to a non-nil io.Reader that
// would return 0 bytes if read, but net/http/Request.outgoingLength takes the
// presence of a body to indicate that length > 0 and "corrects" it to -1 to
// indicate unknown. If we don't fix it here we get 411 Length Required errors.
req.Body = nil
task.Headers = append(task.Headers, "Content-Length:0")
}
for _, header := range task.Headers {
parts := strings.SplitN(header, ":", 2)
if len(parts) != 2 {
Expand Down

0 comments on commit 0999f7a

Please sign in to comment.