From 6fc1cd2179e2e7b9d4a8ebb3ac6ed69c1611ed95 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 13 Aug 2020 10:59:57 +0100 Subject: [PATCH] Tweaks --- build/gobind/monolith.go | 2 +- clientapi/routing/routing.go | 10 +++------- cmd/dendrite-demo-libp2p/main.go | 4 ++-- cmd/dendrite-demo-yggdrasil/main.go | 2 +- cmd/dendritejs/main.go | 2 +- federationapi/routing/routing.go | 12 +++--------- mediaapi/routing/routing.go | 7 ++----- syncapi/routing/routing.go | 6 ++---- 8 files changed, 15 insertions(+), 30 deletions(-) diff --git a/build/gobind/monolith.go b/build/gobind/monolith.go index 71a638b43..f45f07b56 100644 --- a/build/gobind/monolith.go +++ b/build/gobind/monolith.go @@ -184,7 +184,7 @@ func (m *DendriteMonolith) Start() { httpRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.ExternalMediaAPIMux) yggRouter := mux.NewRouter() - httpRouter.PathPrefix(httputil.ExternalFederationPathPrefix).Handler(base.ExternalClientAPIMux) + httpRouter.PathPrefix(httputil.ExternalFederationPathPrefix).Handler(base.ExternalFederationAPIMux) httpRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.ExternalMediaAPIMux) // Build both ends of a HTTP multiplex. diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go index 4c96280b6..d40621ec3 100644 --- a/clientapi/routing/routing.go +++ b/clientapi/routing/routing.go @@ -40,10 +40,6 @@ import ( "github.com/matrix-org/util" ) -const pathPrefixV1 = "/api/v1" -const pathPrefixR0 = "/r0" -const pathPrefixUnstable = "/unstable" - // Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client // to clients which need to make outbound HTTP requests. // @@ -84,9 +80,9 @@ func Setup( }), ).Methods(http.MethodGet, http.MethodOptions) - r0mux := publicAPIMux.PathPrefix(pathPrefixR0).Subrouter() - v1mux := publicAPIMux.PathPrefix(pathPrefixV1).Subrouter() - unstableMux := publicAPIMux.PathPrefix(pathPrefixUnstable).Subrouter() + r0mux := publicAPIMux.PathPrefix("/r0").Subrouter() + v1mux := publicAPIMux.PathPrefix("/api/v1").Subrouter() + unstableMux := publicAPIMux.PathPrefix("/unstable").Subrouter() r0mux.Handle("/createRoom", httputil.MakeAuthAPI("createRoom", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse { diff --git a/cmd/dendrite-demo-libp2p/main.go b/cmd/dendrite-demo-libp2p/main.go index f73241312..760dd9cfd 100644 --- a/cmd/dendrite-demo-libp2p/main.go +++ b/cmd/dendrite-demo-libp2p/main.go @@ -204,8 +204,8 @@ func main() { httpRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.Base.ExternalMediaAPIMux) libp2pRouter := mux.NewRouter() - httpRouter.PathPrefix(httputil.ExternalFederationPathPrefix).Handler(base.Base.ExternalClientAPIMux) - httpRouter.PathPrefix(httputil.ExternalKeyPathPrefix).Handler(base.Base.ExternalClientAPIMux) + httpRouter.PathPrefix(httputil.ExternalFederationPathPrefix).Handler(base.Base.ExternalFederationAPIMux) + httpRouter.PathPrefix(httputil.ExternalKeyPathPrefix).Handler(base.Base.ExternalKeyAPIMux) httpRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.Base.ExternalMediaAPIMux) // Expose the matrix APIs directly rather than putting them under a /api path. diff --git a/cmd/dendrite-demo-yggdrasil/main.go b/cmd/dendrite-demo-yggdrasil/main.go index 52fe07422..5e734fadc 100644 --- a/cmd/dendrite-demo-yggdrasil/main.go +++ b/cmd/dendrite-demo-yggdrasil/main.go @@ -169,7 +169,7 @@ func main() { httpRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.ExternalMediaAPIMux) yggRouter := mux.NewRouter() - httpRouter.PathPrefix(httputil.ExternalFederationPathPrefix).Handler(base.ExternalClientAPIMux) + httpRouter.PathPrefix(httputil.ExternalFederationPathPrefix).Handler(base.ExternalFederationAPIMux) httpRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.ExternalMediaAPIMux) // Build both ends of a HTTP multiplex. diff --git a/cmd/dendritejs/main.go b/cmd/dendritejs/main.go index 540912af2..39fb06f4a 100644 --- a/cmd/dendritejs/main.go +++ b/cmd/dendritejs/main.go @@ -248,7 +248,7 @@ func main() { httpRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.ExternalMediaAPIMux) libp2pRouter := mux.NewRouter() - httpRouter.PathPrefix(httputil.ExternalFederationPathPrefix).Handler(base.ExternalClientAPIMux) + httpRouter.PathPrefix(httputil.ExternalFederationPathPrefix).Handler(base.ExternalFederationAPIMux) httpRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.ExternalMediaAPIMux) // Expose the matrix APIs via libp2p-js - for federation traffic diff --git a/federationapi/routing/routing.go b/federationapi/routing/routing.go index 619296488..650ef16df 100644 --- a/federationapi/routing/routing.go +++ b/federationapi/routing/routing.go @@ -31,12 +31,6 @@ import ( "github.com/matrix-org/util" ) -const ( - pathPrefixV2Keys = "/v2" - pathPrefixV1Federation = "/v1" - pathPrefixV2Federation = "/v2" -) - // Setup registers HTTP handlers with the given ServeMux. // The provided publicAPIMux MUST have `UseEncodedPath()` enabled or else routes will incorrectly // path unescape twice (once from the router, once from MakeFedAPI). We need to have this enabled @@ -57,9 +51,9 @@ func Setup( stateAPI currentstateAPI.CurrentStateInternalAPI, keyAPI keyserverAPI.KeyInternalAPI, ) { - v2keysmux := keyMux.PathPrefix(pathPrefixV2Keys).Subrouter() - v1fedmux := fedMux.PathPrefix(pathPrefixV1Federation).Subrouter() - v2fedmux := fedMux.PathPrefix(pathPrefixV2Federation).Subrouter() + v2keysmux := keyMux.PathPrefix("/v2").Subrouter() + v1fedmux := fedMux.PathPrefix("/v1").Subrouter() + v2fedmux := fedMux.PathPrefix("/v2").Subrouter() wakeup := &httputil.FederationWakeups{ FsAPI: fsAPI, diff --git a/mediaapi/routing/routing.go b/mediaapi/routing/routing.go index ee5f28f93..e4523c096 100644 --- a/mediaapi/routing/routing.go +++ b/mediaapi/routing/routing.go @@ -32,9 +32,6 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" ) -const pathPrefixR0 = "/media/r0" -const pathPrefixV1 = "/media/v1" // TODO: remove when synapse is fixed - // Setup registers the media API HTTP handlers // // Due to Setup being used to call many other functions, a gocyclo nolint is @@ -47,8 +44,8 @@ func Setup( userAPI userapi.UserInternalAPI, client *gomatrixserverlib.Client, ) { - r0mux := publicAPIMux.PathPrefix(pathPrefixR0).Subrouter() - v1mux := publicAPIMux.PathPrefix(pathPrefixV1).Subrouter() + r0mux := publicAPIMux.PathPrefix("/media/r0").Subrouter() + v1mux := publicAPIMux.PathPrefix("/media/v1").Subrouter() activeThumbnailGeneration := &types.ActiveThumbnailGeneration{ PathToResult: map[string]*types.ThumbnailGenerationResult{}, diff --git a/syncapi/routing/routing.go b/syncapi/routing/routing.go index ec21c1b43..f42679c67 100644 --- a/syncapi/routing/routing.go +++ b/syncapi/routing/routing.go @@ -28,20 +28,18 @@ import ( "github.com/matrix-org/util" ) -const pathPrefixR0 = "/client/r0" - // Setup configures the given mux with sync-server listeners // // Due to Setup being used to call many other functions, a gocyclo nolint is // applied: // nolint: gocyclo func Setup( - publicAPIMux *mux.Router, srp *sync.RequestPool, syncDB storage.Database, + csMux *mux.Router, srp *sync.RequestPool, syncDB storage.Database, userAPI userapi.UserInternalAPI, federation *gomatrixserverlib.FederationClient, rsAPI api.RoomserverInternalAPI, cfg *config.SyncAPI, ) { - r0mux := publicAPIMux.PathPrefix(pathPrefixR0).Subrouter() + r0mux := csMux.PathPrefix("/r0").Subrouter() // TODO: Add AS support for all handlers below. r0mux.Handle("/sync", httputil.MakeAuthAPI("sync", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {