mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 23:48:27 +00:00
Return M_UNRECOGNIZED
for unknown CS API endpoints/actions (#2740)
Fixes #2739.
This commit is contained in:
parent
249b32c4f3
commit
6c67552bf9
1 changed files with 12 additions and 3 deletions
|
@ -392,17 +392,26 @@ func (b *BaseDendrite) configureHTTPErrors() {
|
||||||
_, _ = w.Write([]byte(fmt.Sprintf("405 %s not allowed on this endpoint", r.Method)))
|
_, _ = w.Write([]byte(fmt.Sprintf("405 %s not allowed on this endpoint", r.Method)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clientNotFoundHandler := func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
_, _ = w.Write([]byte(`{"errcode":"M_UNRECOGNIZED","error":"Unrecognized request"}`)) // nolint:misspell
|
||||||
|
}
|
||||||
|
|
||||||
notFoundCORSHandler := httputil.WrapHandlerInCORS(http.NotFoundHandler())
|
notFoundCORSHandler := httputil.WrapHandlerInCORS(http.NotFoundHandler())
|
||||||
notAllowedCORSHandler := httputil.WrapHandlerInCORS(http.HandlerFunc(notAllowedHandler))
|
notAllowedCORSHandler := httputil.WrapHandlerInCORS(http.HandlerFunc(notAllowedHandler))
|
||||||
|
|
||||||
for _, router := range []*mux.Router{
|
for _, router := range []*mux.Router{
|
||||||
b.PublicClientAPIMux, b.PublicMediaAPIMux,
|
b.PublicMediaAPIMux, b.DendriteAdminMux,
|
||||||
b.DendriteAdminMux, b.SynapseAdminMux,
|
b.SynapseAdminMux, b.PublicWellKnownAPIMux,
|
||||||
b.PublicWellKnownAPIMux,
|
|
||||||
} {
|
} {
|
||||||
router.NotFoundHandler = notFoundCORSHandler
|
router.NotFoundHandler = notFoundCORSHandler
|
||||||
router.MethodNotAllowedHandler = notAllowedCORSHandler
|
router.MethodNotAllowedHandler = notAllowedCORSHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Special case so that we don't upset clients on the CS API.
|
||||||
|
b.PublicClientAPIMux.NotFoundHandler = http.HandlerFunc(clientNotFoundHandler)
|
||||||
|
b.PublicClientAPIMux.MethodNotAllowedHandler = http.HandlerFunc(clientNotFoundHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupAndServeHTTP sets up the HTTP server to serve endpoints registered on
|
// SetupAndServeHTTP sets up the HTTP server to serve endpoints registered on
|
||||||
|
|
Loading…
Reference in a new issue