From 0ce5e57c30c45322d49a37abfbabdb8587281029 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 22 Dec 2022 15:42:47 +0000 Subject: [PATCH] serve webdav: fix --baseurl handling after lib/http refactor The webdav library was confused by the Path manipulation done by lib/http when stripping the prefix. This patch adds the prefix back before calling it. Fixes #6650 --- cmd/serve/webdav/webdav.go | 3 +++ cmd/serve/webdav/webdav_test.go | 1 + 2 files changed, 4 insertions(+) diff --git a/cmd/serve/webdav/webdav.go b/cmd/serve/webdav/webdav.go index 00af1f033..cdec88b4b 100644 --- a/cmd/serve/webdav/webdav.go +++ b/cmd/serve/webdav/webdav.go @@ -237,6 +237,9 @@ func (w *WebDAV) ServeHTTP(rw http.ResponseWriter, r *http.Request) { w.serveDir(rw, r, remote) return } + // Add URL Prefix back to path since webdavhandler needs to + // return absolute references. + r.URL.Path = w.opt.HTTP.BaseURL + r.URL.Path w.webdavhandler.ServeHTTP(rw, r) } diff --git a/cmd/serve/webdav/webdav_test.go b/cmd/serve/webdav/webdav_test.go index fa0626075..2bc61a58a 100644 --- a/cmd/serve/webdav/webdav_test.go +++ b/cmd/serve/webdav/webdav_test.go @@ -51,6 +51,7 @@ func TestWebDav(t *testing.T) { start := func(f fs.Fs) (configmap.Simple, func()) { opt := DefaultOpt opt.HTTP.ListenAddr = []string{testBindAddress} + opt.HTTP.BaseURL = "/prefix" opt.Auth.BasicUser = testUser opt.Auth.BasicPass = testPass opt.Template.Path = testTemplate