From 82e24f521f3dddb9909bb5f4b52dd69d96a04889 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 26 Apr 2022 08:58:31 +0100 Subject: [PATCH] webdav: don't override Referer if user sets it - fixes #6040 --- backend/webdav/webdav.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/backend/webdav/webdav.go b/backend/webdav/webdav.go index 9564ae601..77fcf93d1 100644 --- a/backend/webdav/webdav.go +++ b/backend/webdav/webdav.go @@ -454,7 +454,9 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e if err != nil { return nil, err } - f.srv.SetHeader("Referer", u.String()) + if !f.findHeader(opt.Headers, "Referer") { + f.srv.SetHeader("Referer", u.String()) + } if root != "" && !rootIsDir { // Check to see if the root actually an existing file @@ -517,6 +519,17 @@ func (f *Fs) addHeaders(headers fs.CommaSepList) { } } +// Returns true if the header was configured +func (f *Fs) findHeader(headers fs.CommaSepList, find string) bool { + for i := 0; i < len(headers); i += 2 { + key := f.opt.Headers[i] + if strings.EqualFold(key, find) { + return true + } + } + return false +} + // fetch the bearer token and set it if successful func (f *Fs) fetchAndSetBearerToken() error { if f.opt.BearerTokenCommand == "" {