Monday 26 February 2018

[Question] How to terminate a Server Sent Events session?

I intercept a request using express (which I use to handle other routes), then initiate a SSE session by directly setting headers on the response:res.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-cache" }); I proceed with writing intermittent payloads using "res.write()".** It's worth noting that since I don't report a "content-length", Node automatically assumes "chunked" transfer encoding (this shouldn't be a problem AFAIK). It also defaults to "connection: keep-alive".This works well with Chrome's EventSource, up until the point when I call ".close()" to end the session. Then, the connection keeps hanging: Chrome doesn't reuse the connection to initiate additional EventSource requests (or other), and node doesn't supply a "close" event on the IncomingMessage instance.My question is: How do I handle "eventSource.close()" properly using node's http entities?

Submitted February 26, 2018 at 10:40AM by tweinf

No comments:

Post a Comment