Skip to content

Commit

Permalink
return gone when endpoint deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
otherview committed Dec 18, 2024
1 parent d733708 commit 59742ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions api/subscriptions/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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))
}
}
2 changes: 1 addition & 1 deletion api/subscriptions/subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 59742ee

Please sign in to comment.