Use built-in HTTP 404 handler

This commit is contained in:
Neil Alexander 2022-08-01 11:11:51 +01:00
parent 7c8caa9951
commit 4f547fadc5
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -370,16 +370,12 @@ func (b *BaseDendrite) CreateFederationClient() *gomatrixserverlib.FederationCli
}
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)))
_, _ = w.Write([]byte(fmt.Sprintf("405 %s not allowed on this endpoint", r.Method)))
}
notFoundCORSHandler := httputil.WrapHandlerInCORS(http.HandlerFunc(notFoundHandler))
notFoundCORSHandler := httputil.WrapHandlerInCORS(http.NotFoundHandler())
notAllowedCORSHandler := httputil.WrapHandlerInCORS(http.HandlerFunc(notAllowedHandler))
for _, router := range []*mux.Router{