Fix the routing capability (#6921)

Co-authored-by: Roman Perekhod <rperekhod@owncloud.com>
This commit is contained in:
Roman Perekhod
2023-07-31 13:23:41 +02:00
committed by GitHub
parent c93b65680b
commit 526583e9bb
2 changed files with 27 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
Bugfix: Fix the routing capability
Fix the routing capability
https://github.com/owncloud/web/issues/9367

View File

@@ -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
}