diff --git a/changelog/unreleased/fix-routing.md b/changelog/unreleased/fix-routing.md new file mode 100644 index 0000000000..8755c3641a --- /dev/null +++ b/changelog/unreleased/fix-routing.md @@ -0,0 +1,5 @@ +Bugfix: Fix the routing capability + +Fix the routing capability + +https://github.com/owncloud/web/issues/9367 diff --git a/services/webdav/pkg/service/v0/service.go b/services/webdav/pkg/service/v0/service.go index ea6eb2a526..874d27a0cf 100644 --- a/services/webdav/pkg/service/v0/service.go +++ b/services/webdav/pkg/service/v0/service.go @@ -124,11 +124,7 @@ func NewService(opts ...Option) (Service, error) { // After the issue has been solved upstream in go-chi we should switch // back to using `chi.RegisterMethod`. m.MethodNotAllowed(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - routePrefix := path.Join(options.Config.HTTP.Root, "/remote.php/dav/files/") - spacesPrefix := path.Join(options.Config.HTTP.Root, "/dav/spaces/") - legacyRoutePrefix := path.Join(options.Config.HTTP.Root, "/remote.php/webdav") - if req.Method == "REPORT" && - (strings.HasPrefix(req.URL.Path, spacesPrefix) || strings.HasPrefix(req.URL.Path, routePrefix) || strings.HasPrefix(req.URL.Path, legacyRoutePrefix)) { + if req.Method == "REPORT" && pathHasPrefix(req.URL.Path, options.Config.HTTP.Root) { // The URLParam will not be available here. If it is needed it // needs to be passed manually or chi needs to be fixed // To use it properly. @@ -540,3 +536,24 @@ func renderError(w http.ResponseWriter, r *http.Request, err *errResponse) { func notFoundMsg(name string) string { return "File with name " + name + " could not be located" } + +// This is a workaround for the go-chi concurrent map read write issue. +// After the issue has been solved upstream in go-chi we should switch +// back to using `chi.RegisterMethod`. +var prefixList = []string{ + "/remote.php/dav/files/", + "/remote.php/dav/spaces/", + "/remote.php/webdav", + "/dav/files/", + "/dav/spaces/", + "/webdav", +} + +func pathHasPrefix(reqPath, root string) bool { + for _, p := range prefixList { + if strings.HasPrefix(reqPath, path.Join(root, p)) { + return true + } + } + return false +}