From 71e2ae7421f578c3ff9885796c94620aa8a377ca Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 27 Jul 2021 20:02:58 +0100 Subject: [PATCH] Rewrite URL --- clientapi/routing/routing.go | 5 ++++- federationapi/routing/routing.go | 6 ------ syncapi/routing/routing.go | 6 +++++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go index 0a2efd6cc..0251a8fde 100644 --- a/clientapi/routing/routing.go +++ b/clientapi/routing/routing.go @@ -117,7 +117,10 @@ func Setup( r0mux := publicAPIMux.PathPrefix("/r0").Subrouter() unstableMux := publicAPIMux.PathPrefix("/unstable").Subrouter() - unstableMux.NotFoundHandler = r0mux // serve r0 endpoints by default unless overridden + defer unstableMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + r.URL.Path = strings.Replace(r.URL.Path, "/unstable/", "/r0/", 1) + r0mux.ServeHTTP(w, r) + }) // serve r0 endpoints by default unless overridden r0mux.Handle("/createRoom", httputil.MakeAuthAPI("createRoom", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse { diff --git a/federationapi/routing/routing.go b/federationapi/routing/routing.go index c479e3d93..8f33c7660 100644 --- a/federationapi/routing/routing.go +++ b/federationapi/routing/routing.go @@ -57,12 +57,6 @@ func Setup( v1fedmux := fedMux.PathPrefix("/v1").Subrouter() v2fedmux := fedMux.PathPrefix("/v2").Subrouter() - unstableFedMux := fedMux.PathPrefix("/unstable").Subrouter() - unstableFedMux.NotFoundHandler = v2fedmux // serve v2 endpoints by default unless overridden - - unstableKeysMux := keyMux.PathPrefix("/unstable").Subrouter() - unstableKeysMux.NotFoundHandler = v2keysmux // serve v2 endpoints by default unless overridden - wakeup := &httputil.FederationWakeups{ FsAPI: fsAPI, } diff --git a/syncapi/routing/routing.go b/syncapi/routing/routing.go index 1ffd3cb26..f4aec1d71 100644 --- a/syncapi/routing/routing.go +++ b/syncapi/routing/routing.go @@ -16,6 +16,7 @@ package routing import ( "net/http" + "strings" "github.com/gorilla/mux" "github.com/matrix-org/dendrite/internal/httputil" @@ -41,7 +42,10 @@ func Setup( ) { r0mux := csMux.PathPrefix("/r0").Subrouter() unstableMux := csMux.PathPrefix("/unstable").Subrouter() - unstableMux.NotFoundHandler = r0mux // serve r0 endpoints by default unless overridden + defer unstableMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + r.URL.Path = strings.Replace(r.URL.Path, "/unstable/", "/r0/", 1) + r0mux.ServeHTTP(w, r) + }) // serve r0 endpoints by default unless overridden // TODO: Add AS support for all handlers below. r0mux.Handle("/sync", httputil.MakeAuthAPI("sync", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {