Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

properly register webdav methods with chi #4091

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/register-methods-with-chi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: register WebDAV HTTP methods with chi

We now correctly register the WebDAV methods with chi during init.

https://github.com/cs3org/reva/pull/4091
https://github.com/owncloud/ocis/issues/6924
27 changes: 12 additions & 15 deletions pkg/micro/ocdav/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ import (
"go.opentelemetry.io/otel/trace"
)

func init() {
// register method with chi before any routing is set up
chi.RegisterMethod(ocdav.MethodPropfind)
chi.RegisterMethod(ocdav.MethodProppatch)
chi.RegisterMethod(ocdav.MethodLock)
chi.RegisterMethod(ocdav.MethodUnlock)
chi.RegisterMethod(ocdav.MethodCopy)
chi.RegisterMethod(ocdav.MethodMove)
chi.RegisterMethod(ocdav.MethodMkcol)
chi.RegisterMethod(ocdav.MethodReport)
}

const (
// ServerName to use when announcing the service to the registry
ServerName = "ocdav"
Expand Down Expand Up @@ -73,17 +85,6 @@ func Service(opts ...Option) (micro.Service, error) {
return nil, err
}

// Comment back in after resolving the issue in go-chi.
// See comment in line 87.
// register additional webdav verbs
// chi.RegisterMethod(ocdav.MethodPropfind)
// chi.RegisterMethod(ocdav.MethodProppatch)
// chi.RegisterMethod(ocdav.MethodLock)
// chi.RegisterMethod(ocdav.MethodUnlock)
// chi.RegisterMethod(ocdav.MethodCopy)
// chi.RegisterMethod(ocdav.MethodMove)
// chi.RegisterMethod(ocdav.MethodMkcol)
// chi.RegisterMethod(ocdav.MethodReport)
r := chi.NewRouter()
tp := sopts.TraceProvider

Expand All @@ -107,10 +108,6 @@ func Service(opts ...Option) (micro.Service, error) {
}

r.Handle("/*", revaService.Handler())
// 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`.
r.MethodNotAllowed(http.HandlerFunc(revaService.Handler().ServeHTTP))

_ = chi.Walk(r, func(method string, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error {
sopts.Logger.Debug().Str("service", "ocdav").Str("method", method).Str("route", route).Int("middlewares", len(middlewares)).Msg("serving endpoint")
Expand Down