From 1550f70865245f917c63330039b18876bb214c8f Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 18 Jun 2018 12:22:13 +0100 Subject: [PATCH] webdav: Don't accept redirects when reading metadata #2350 Go can't redirect PROPFIND requests properly, it changes the method to GET, so we disable redirects when reading the metadata and assume the object does not exist if we receive a redirect. This is to work-around the qnap redirecting requests for directories without /. --- backend/webdav/webdav.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/webdav/webdav.go b/backend/webdav/webdav.go index ba4e75cab..d5e1250c3 100644 --- a/backend/webdav/webdav.go +++ b/backend/webdav/webdav.go @@ -182,6 +182,7 @@ func (f *Fs) readMetaDataForPath(path string) (info *api.Prop, err error) { ExtraHeaders: map[string]string{ "Depth": "1", }, + NoRedirect: true, } var result api.Multistatus var resp *http.Response @@ -191,7 +192,13 @@ func (f *Fs) readMetaDataForPath(path string) (info *api.Prop, err error) { }) if apiErr, ok := err.(*api.Error); ok { // does not exist - if apiErr.StatusCode == http.StatusNotFound { + switch apiErr.StatusCode { + case http.StatusNotFound: + return nil, fs.ErrorObjectNotFound + case http.StatusMovedPermanently, http.StatusFound, http.StatusSeeOther: + // Some sort of redirect - go doesn't deal with these properly (it resets + // the method to GET). However we can assume that if it was redirected the + // object was not found. return nil, fs.ErrorObjectNotFound } }