Skip to content

Commit

Permalink
Merge pull request #4091 from butonic/register-chi-routes
Browse files Browse the repository at this point in the history
properly register webdav methods with chi
  • Loading branch information
micbar authored Aug 1, 2023
2 parents 8e6c45f + a2a3e41 commit d830693
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
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

0 comments on commit d830693

Please sign in to comment.