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

implement workaround for chi.RegisterMethod #3662

Merged
merged 1 commit into from
May 3, 2022
Merged
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
22 changes: 20 additions & 2 deletions extensions/webdav/pkg/service/v0/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/xml"
"io"
"net/http"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -52,7 +53,9 @@ func NewService(opts ...Option) (Service, error) {
conf := options.Config

m := chi.NewMux()
chi.RegisterMethod("REPORT")
// Comment back in after resolving the issue in go-chi.
// See comment in line 82.
// chi.RegisterMethod("REPORT")
m.Use(options.Middleware...)

gwc, err := pool.GetGatewayServiceClient(conf.RevaGateway)
Expand All @@ -75,7 +78,22 @@ func NewService(opts ...Option) (Service, error) {
r.Get("/remote.php/dav/public-files/{token}/*", svc.PublicThumbnail)
r.Head("/remote.php/dav/public-files/{token}/*", svc.PublicThumbnailHead)

r.MethodFunc("REPORT", "/remote.php/dav/files/{id}/*", 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) {
routePrefix := path.Join(options.Config.HTTP.Root, "/remote.php/dav/files/")
if req.Method == "REPORT" && strings.HasPrefix(req.URL.Path, routePrefix) {
// 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)
}))
})

return svc, nil
Expand Down