diff --git a/api/subscriptions/subscriptions.go b/api/subscriptions/subscriptions.go index b343d0c24..f4f29d576 100644 --- a/api/subscriptions/subscriptions.go +++ b/api/subscriptions/subscriptions.go @@ -374,6 +374,13 @@ func (s *Subscriptions) websocket(readerFunc func(http.ResponseWriter, *http.Req } } +// handleGone is a handler for deprecated endpoints that returns HTTP 410 Gone. +func handleGone(w http.ResponseWriter, _ *http.Request) error { + w.WriteHeader(http.StatusGone) + _, _ = w.Write([]byte("This endpoint is no longer supported.")) + return nil +} + func (s *Subscriptions) Mount(root *mux.Router, pathPrefix string) { sub := root.PathPrefix(pathPrefix).Subrouter() @@ -402,10 +409,13 @@ func (s *Subscriptions) Mount(root *mux.Router, pathPrefix string) { Name("subscriptions_beat2"). HandlerFunc(utils.WrapHandlerFunc(s.websocket(s.handleBeat2Reader))) + deprecatedBeat := sub.Path("/beat"). + Methods(http.MethodGet). + Name("subscriptions_beat") + if s.enabledDeprecated { - sub.Path("/beat"). - Methods(http.MethodGet). - Name("subscriptions_beat"). - HandlerFunc(utils.WrapHandlerFunc(s.websocket(s.handleBeatReader))) + deprecatedBeat.HandlerFunc(utils.WrapHandlerFunc(s.websocket(s.handleBeatReader))) + } else { + deprecatedBeat.HandlerFunc(utils.WrapHandlerFunc(handleGone)) } } diff --git a/api/subscriptions/subscriptions_test.go b/api/subscriptions/subscriptions_test.go index 5cb6110c9..8cfb55f7f 100644 --- a/api/subscriptions/subscriptions_test.go +++ b/api/subscriptions/subscriptions_test.go @@ -59,7 +59,7 @@ func TestDeprecatedSubscriptions(t *testing.T) { _, resp, err := websocket.DefaultDialer.Dial(u.String(), nil) assert.Error(t, err) - assert.Equal(t, http.StatusNotFound, resp.StatusCode) + assert.Equal(t, http.StatusGone, resp.StatusCode) } func testHandleSubjectWithBlock(t *testing.T) {