Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

webdav: permit redirects on PROPFIND for metadata

Brian Bockelmancf240b6c0f84
diff --git a/backend/webdav/webdav.go b/backend/webdav/webdav.go
index 09746f2b6..ccf48e957 100644
--- a/backend/webdav/webdav.go
+++ b/backend/webdav/webdav.go
@@ -348,7 +348,7 @@ func (f *Fs) readMetaDataForPath(ctx context.Context, path string, depth string)
ExtraHeaders: map[string]string{
"Depth": depth,
},
- NoRedirect: true,
+ CheckRedirect: rest.PreserveMethodRedirectFn,
}
if f.hasOCMD5 || f.hasOCSHA1 {
opts.Body = bytes.NewBuffer(owncloudProps)
diff --git a/lib/rest/rest.go b/lib/rest/rest.go
index f8771f106..3a36a0343 100644
--- a/lib/rest/rest.go
+++ b/lib/rest/rest.go
@@ -215,6 +215,22 @@ func ClientWithNoRedirects(c *http.Client) *http.Client {
return &clientCopy
}
+// PreserveMethodRedirectFn is a CheckRedirect function that
+// preserves the original HTTP method on redirects.
+//
+// By default Go's http.Client changes the method to GET on 301, 302,
+// and 303 redirects. This function overrides that behaviour so the
+// original method (e.g. PROPFIND being preserved across a 307) is kept.
+func PreserveMethodRedirectFn(req *http.Request, via []*http.Request) error {
+ if len(via) >= 10 {
+ return errors.New("stopped after 10 redirects")
+ }
+ if len(via) > 0 {
+ req.Method = via[0].Method
+ }
+ return nil
+}
+
// Do calls the internal http.Client.Do method
func (api *Client) Do(req *http.Request) (*http.Response, error) {
return api.c.Do(req)