diff --git a/services/proxy/pkg/command/server.go b/services/proxy/pkg/command/server.go index edc3d10bde..be565f7fc1 100644 --- a/services/proxy/pkg/command/server.go +++ b/services/proxy/pkg/command/server.go @@ -198,16 +198,12 @@ func (h *StaticRouteHandler) handler() http.Handler { r.Post("/backchannel_logout", h.backchannelLogout) // TODO: migrate oidc well knowns here in a second wrapper + + // Send all requests to the proxy handler r.HandleFunc("/*", h.proxy.ServeHTTP) }) - // This is commented out due to a race issue in chi - //var methods = []string{"PROPFIND", "DELETE", "PROPPATCH", "MKCOL", "COPY", "MOVE", "LOCK", "UNLOCK", "REPORT"} - //for _, k := range methods { - // chi.RegisterMethod(k) - //} - // To avoid using the chi.RegisterMethod() this is basically a catchAll for all HTTP Methods that are not - // covered in chi by default + // Also send requests for methods unknown to chi to the proxy handler as well m.MethodNotAllowed(h.proxy.ServeHTTP) return m diff --git a/services/proxy/pkg/config/defaults/defaultconfig.go b/services/proxy/pkg/config/defaults/defaultconfig.go index 16ee92d710..6874139943 100644 --- a/services/proxy/pkg/config/defaults/defaultconfig.go +++ b/services/proxy/pkg/config/defaults/defaultconfig.go @@ -151,18 +151,9 @@ func DefaultPolicies() []config.Policy { // TODO or we allow a REPORT on /dav/spaces to search all spaces and /dav/space/{spaceid} to search a specific space // send webdav REPORT requests to search service { + Type: config.RegexRoute, Method: "REPORT", - Endpoint: "/remote.php/dav/", - Service: "com.owncloud.web.webdav", - }, - { - Method: "REPORT", - Endpoint: "/remote.php/webdav", - Service: "com.owncloud.web.webdav", - }, - { - Method: "REPORT", - Endpoint: "/dav/spaces", + Endpoint: "(/remote.php)?/(web)?dav", Service: "com.owncloud.web.webdav", }, { diff --git a/services/webdav/pkg/service/v0/service.go b/services/webdav/pkg/service/v0/service.go index 874d27a0cf..e7b0716295 100644 --- a/services/webdav/pkg/service/v0/service.go +++ b/services/webdav/pkg/service/v0/service.go @@ -29,6 +29,11 @@ import ( "google.golang.org/grpc/metadata" ) +func init() { + // register method with chi before any routing is set up + chi.RegisterMethod("REPORT") +} + const ( TokenHeader = "X-Access-Token" ) @@ -54,9 +59,6 @@ func NewService(opts ...Option) (Service, error) { conf := options.Config m := chi.NewMux() - // Comment back in after resolving the issue in go-chi. - // See comment in line 82. - // chi.RegisterMethod("REPORT") m.Use(options.Middleware...) tm, err := pool.StringToTLSMode(conf.GRPCClientTLS.Mode) @@ -94,11 +96,15 @@ func NewService(opts ...Option) (Service, error) { r.Get("/remote.php/dav/spaces/{id}/*", svc.SpacesThumbnail) r.Get("/dav/spaces/{id}", svc.SpacesThumbnail) r.Get("/dav/spaces/{id}/*", svc.SpacesThumbnail) + r.MethodFunc("REPORT", "/remote.php/dav/spaces*", svc.Search) + r.MethodFunc("REPORT", "/dav/spaces*", svc.Search) r.Get("/remote.php/dav/files/{id}", svc.Thumbnail) r.Get("/remote.php/dav/files/{id}/*", svc.Thumbnail) r.Get("/dav/files/{id}", svc.Thumbnail) r.Get("/dav/files/{id}/*", svc.Thumbnail) + r.MethodFunc("REPORT", "/remote.php/dav/files*", svc.Search) + r.MethodFunc("REPORT", "/dav/files*", svc.Search) }) r.Group(func(r chi.Router) { @@ -115,24 +121,12 @@ func NewService(opts ...Option) (Service, error) { r.Use(svc.WebDAVContext()) r.Get("/remote.php/webdav/*", svc.Thumbnail) r.Get("/webdav/*", svc.Thumbnail) + + r.MethodFunc("REPORT", "/remote.php/webdav*", svc.Search) + r.MethodFunc("REPORT", "/webdav*", svc.Search) }) } - // r.MethodFunc("REPORT", "/remote.php/dav/files/{id}/*", svc.Search) - - // 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`. - m.MethodNotAllowed(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - 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. - svc.Search(w, req) - return - } - w.WriteHeader(http.StatusMethodNotAllowed) - })) }) _ = chi.Walk(m, func(method string, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error { @@ -536,24 +530,3 @@ 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 -}