mirror of
https://github.com/rclone/rclone.git
synced 2025-08-19 01:46:31 +02:00
rest: fix upload of 0 length files
Before this change if ContentLength was set in the options but 0 then we would upload using chunked encoding. Fix this to always upload with a "Content-Length" header even if the size is 0. Remove workarounds for this from b2 and onedrive backends. This fixes the issue for the webdav backend described here: https://forum.rclone.org/t/code-500-errors-with-webdav-nextcloud/8440/
This commit is contained in:
@@ -198,7 +198,17 @@ func (api *Client) Call(opts *Opts) (resp *http.Response, err error) {
|
||||
if opts.Parameters != nil && len(opts.Parameters) > 0 {
|
||||
url += "?" + opts.Parameters.Encode()
|
||||
}
|
||||
req, err := http.NewRequest(opts.Method, url, opts.Body)
|
||||
body := opts.Body
|
||||
// If length is set and zero then nil out the body to stop use
|
||||
// use of chunked encoding and insert a "Content-Length: 0"
|
||||
// header.
|
||||
//
|
||||
// If we don't do this we get "Content-Length" headers for all
|
||||
// files except 0 length files.
|
||||
if opts.ContentLength != nil && *opts.ContentLength == 0 {
|
||||
body = nil
|
||||
}
|
||||
req, err := http.NewRequest(opts.Method, url, body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user