mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-09 07:03:10 -06:00
Tidy up some more
This commit is contained in:
parent
379b5058ab
commit
7c8caa9951
|
|
@ -369,6 +369,31 @@ func (b *BaseDendrite) CreateFederationClient() *gomatrixserverlib.FederationCli
|
||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *BaseDendrite) configureHTTPErrors(internalRouter, externalRouter *mux.Router) {
|
||||||
|
notFoundHandler := func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
_, _ = w.Write([]byte("HTTP 404: endpoint not found"))
|
||||||
|
}
|
||||||
|
notAllowedHandler := func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
|
_, _ = w.Write([]byte(fmt.Sprintf("HTTP 405: %s not allowed on this endpoint", r.Method)))
|
||||||
|
}
|
||||||
|
|
||||||
|
notFoundCORSHandler := httputil.WrapHandlerInCORS(http.HandlerFunc(notFoundHandler))
|
||||||
|
notAllowedCORSHandler := httputil.WrapHandlerInCORS(http.HandlerFunc(notAllowedHandler))
|
||||||
|
|
||||||
|
for _, router := range []*mux.Router{
|
||||||
|
internalRouter, externalRouter,
|
||||||
|
b.DendriteAdminMux, b.SynapseAdminMux,
|
||||||
|
b.InternalAPIMux, b.PublicWellKnownAPIMux,
|
||||||
|
b.PublicClientAPIMux, b.PublicFederationAPIMux,
|
||||||
|
b.PublicKeyAPIMux, b.PublicMediaAPIMux,
|
||||||
|
} {
|
||||||
|
router.NotFoundHandler = notFoundCORSHandler
|
||||||
|
router.MethodNotAllowedHandler = notAllowedCORSHandler
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// SetupAndServeHTTP sets up the HTTP server to serve endpoints registered on
|
// SetupAndServeHTTP sets up the HTTP server to serve endpoints registered on
|
||||||
// ApiMux under /api/ and adds a prometheus handler under /metrics.
|
// ApiMux under /api/ and adds a prometheus handler under /metrics.
|
||||||
func (b *BaseDendrite) SetupAndServeHTTP(
|
func (b *BaseDendrite) SetupAndServeHTTP(
|
||||||
|
|
@ -409,28 +434,7 @@ func (b *BaseDendrite) SetupAndServeHTTP(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
notFoundHandler := func(w http.ResponseWriter, r *http.Request) {
|
b.configureHTTPErrors(internalRouter, externalRouter)
|
||||||
w.WriteHeader(http.StatusNotFound)
|
|
||||||
_, _ = w.Write([]byte("endpoint not found"))
|
|
||||||
}
|
|
||||||
notAllowedHandler := func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
|
||||||
_, _ = w.Write([]byte(fmt.Sprintf("%s not allowed on this endpoint", r.Method)))
|
|
||||||
}
|
|
||||||
|
|
||||||
notFoundCORSHandler := httputil.WrapHandlerInCORS(http.HandlerFunc(notFoundHandler))
|
|
||||||
notAllowedCORSHandler := httputil.WrapHandlerInCORS(http.HandlerFunc(notAllowedHandler))
|
|
||||||
|
|
||||||
for _, router := range []*mux.Router{
|
|
||||||
internalRouter, externalRouter,
|
|
||||||
b.DendriteAdminMux, b.SynapseAdminMux,
|
|
||||||
b.InternalAPIMux, b.PublicWellKnownAPIMux,
|
|
||||||
b.PublicClientAPIMux, b.PublicFederationAPIMux,
|
|
||||||
b.PublicKeyAPIMux, b.PublicMediaAPIMux,
|
|
||||||
} {
|
|
||||||
router.NotFoundHandler = notFoundCORSHandler
|
|
||||||
router.MethodNotAllowedHandler = notAllowedCORSHandler
|
|
||||||
}
|
|
||||||
|
|
||||||
internalRouter.PathPrefix(httputil.InternalPathPrefix).Handler(b.InternalAPIMux)
|
internalRouter.PathPrefix(httputil.InternalPathPrefix).Handler(b.InternalAPIMux)
|
||||||
if b.Cfg.Global.Metrics.Enabled {
|
if b.Cfg.Global.Metrics.Enabled {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue