Skip to content

Commit

Permalink
Added 410 Gone responses to EventSub WebSocket server when trying to …
Browse files Browse the repository at this point in the history
…subscribe to an event version that was removed
  • Loading branch information
Xemdo committed Nov 3, 2023
1 parent f7e353f commit 54f4271
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
8 changes: 8 additions & 0 deletions internal/events/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,11 @@ func GetByTriggerAndTransportAndVersion(trigger string, transport string, versio
// Default error
return nil, errors.New("Invalid event")
}

// These events were removed from production
// This does not include any "beta" events, just old production versions
func RemovedEvents() map[string]string {
return map[string]string{
"channel.follow": "1",
}
}
19 changes: 18 additions & 1 deletion internal/events/websocket/mock_server/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,14 @@ func subscriptionPageHandlerPost(w http.ResponseWriter, r *http.Request) {
return
}

// Check if the topic exists
// Check if the topic was deprecated/removed
for e, v := range types.RemovedEvents() {
if body.Type == e && body.Version == v {
handlerResponseErrorGone(w)
return
}
}

_, err = types.GetByTriggerAndTransportAndVersion(body.Type, body.Transport.Method, body.Version)
if err != nil {
handlerResponseErrorBadRequest(w, "The combination of values in the type and version fields is not valid")
Expand Down Expand Up @@ -546,3 +553,13 @@ func handlerResponseErrorInternalServerError(w http.ResponseWriter, message stri
})
w.Write(bytes)
}

func handlerResponseErrorGone(w http.ResponseWriter) {
w.WriteHeader(http.StatusGone)
bytes, _ := json.Marshal(&SubscriptionPostErrorResponse{
Error: "Gone",
Message: "This subscription type is not available.",
Status: 410,
})
w.Write(bytes)
}

0 comments on commit 54f4271

Please sign in to comment.