diff options
author | Neil Alexander <neilalexander@users.noreply.github.com> | 2020-08-13 12:16:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-13 12:16:37 +0100 |
commit | 9677a95afc529d1766d487db46965266c6fbaa6a (patch) | |
tree | d98ccf518a3f8386054f93be4138988def9848be /federationapi | |
parent | 820c56c165ec8f0409d23cd151a7ff89fbe09ffa (diff) |
API setup refactoring (#1266)
* Start HTTP endpoint refactoring
* Update SetupAndServeHTTP
* Fix builds
* Don't set up external listener if no address configured
* TLS HTTP setup
* Break apart client/federation/key/media muxes
* Tweaks
* Fix P2P demos
* Fix media API routing
* Review comments @Kegsay
* Update sample config
* Fix gobind build
* Fix External -> Public in federation API test
Diffstat (limited to 'federationapi')
-rw-r--r-- | federationapi/federationapi.go | 4 | ||||
-rw-r--r-- | federationapi/federationapi_test.go | 12 | ||||
-rw-r--r-- | federationapi/routing/routing.go | 14 |
3 files changed, 8 insertions, 22 deletions
diff --git a/federationapi/federationapi.go b/federationapi/federationapi.go index e838e8e3..9193685a 100644 --- a/federationapi/federationapi.go +++ b/federationapi/federationapi.go @@ -30,7 +30,7 @@ import ( // AddPublicRoutes sets up and registers HTTP handlers on the base API muxes for the FederationAPI component. func AddPublicRoutes( - router *mux.Router, + fedRouter, keyRouter *mux.Router, cfg *config.FederationAPI, userAPI userapi.UserInternalAPI, federation *gomatrixserverlib.FederationClient, @@ -42,7 +42,7 @@ func AddPublicRoutes( keyAPI keyserverAPI.KeyInternalAPI, ) { routing.Setup( - router, cfg, rsAPI, + fedRouter, keyRouter, cfg, rsAPI, eduAPI, federationSenderAPI, keyRing, federation, userAPI, stateAPI, keyAPI, ) diff --git a/federationapi/federationapi_test.go b/federationapi/federationapi_test.go index 331d3329..45346bc0 100644 --- a/federationapi/federationapi_test.go +++ b/federationapi/federationapi_test.go @@ -8,7 +8,6 @@ import ( "github.com/matrix-org/dendrite/federationapi" "github.com/matrix-org/dendrite/internal/config" - "github.com/matrix-org/dendrite/internal/httputil" "github.com/matrix-org/dendrite/internal/setup" "github.com/matrix-org/dendrite/internal/test" "github.com/matrix-org/gomatrix" @@ -32,15 +31,8 @@ func TestRoomsV3URLEscapeDoNot404(t *testing.T) { fsAPI := base.FederationSenderHTTPClient() // TODO: This is pretty fragile, as if anything calls anything on these nils this test will break. // Unfortunately, it makes little sense to instantiate these dependencies when we just want to test routing. - federationapi.AddPublicRoutes(base.PublicAPIMux, &cfg.FederationAPI, nil, nil, keyRing, nil, fsAPI, nil, nil, nil) - httputil.SetupHTTPAPI( - base.BaseMux, - base.PublicAPIMux, - base.InternalAPIMux, - &cfg.Global, - base.UseHTTPAPIs, - ) - baseURL, cancel := test.ListenAndServe(t, base.BaseMux, true) + federationapi.AddPublicRoutes(base.PublicFederationAPIMux, base.PublicKeyAPIMux, &cfg.FederationAPI, nil, nil, keyRing, nil, fsAPI, nil, nil, nil) + baseURL, cancel := test.ListenAndServe(t, base.PublicFederationAPIMux, true) defer cancel() serverName := gomatrixserverlib.ServerName(strings.TrimPrefix(baseURL, "https://")) diff --git a/federationapi/routing/routing.go b/federationapi/routing/routing.go index 027827fa..650ef16d 100644 --- a/federationapi/routing/routing.go +++ b/federationapi/routing/routing.go @@ -31,12 +31,6 @@ import ( "github.com/matrix-org/util" ) -const ( - pathPrefixV2Keys = "/key/v2" - pathPrefixV1Federation = "/federation/v1" - pathPrefixV2Federation = "/federation/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 @@ -46,7 +40,7 @@ const ( // applied: // nolint: gocyclo func Setup( - publicAPIMux *mux.Router, + fedMux, keyMux *mux.Router, cfg *config.FederationAPI, rsAPI roomserverAPI.RoomserverInternalAPI, eduAPI eduserverAPI.EDUServerInputAPI, @@ -57,9 +51,9 @@ func Setup( stateAPI currentstateAPI.CurrentStateInternalAPI, keyAPI keyserverAPI.KeyInternalAPI, ) { - v2keysmux := publicAPIMux.PathPrefix(pathPrefixV2Keys).Subrouter() - v1fedmux := publicAPIMux.PathPrefix(pathPrefixV1Federation).Subrouter() - v2fedmux := publicAPIMux.PathPrefix(pathPrefixV2Federation).Subrouter() + v2keysmux := keyMux.PathPrefix("/v2").Subrouter() + v1fedmux := fedMux.PathPrefix("/v1").Subrouter() + v2fedmux := fedMux.PathPrefix("/v2").Subrouter() wakeup := &httputil.FederationWakeups{ FsAPI: fsAPI, |