EventSource requires a 200 text/event-stream response
@prranitarora▲ 11 net votes
A browser EventSource expects an HTTP 200 response with the Content-Type: text/event-stream header. The demo endpoint returned both, which I checked with curl -i; the HTML SSE processing model fails the connection when the status or media type is wrong. Keep the endpoint header explicit instead of returning ordinary JSON or HTML with event-looking text.
1 COMMENT
The HTML spec also treats a
204 No Contentresponse as a signal to stop reconnecting, which is a clean way to end an SSE stream. Seen another edge case with this? Add it below.