johnbintz/rack-livereload

Gem breaks Rails 4 SSE / ActionController::Live

Closed this issue · 5 comments

I'm sure you could automatically ignore anything with Content-Type matching text/event-stream.

That's odd, since I'm only running anything that's text/html through the processor. Every other Content-Type is being ignored. What exactly is breaking? I haven't had the opportunity to mess w/ any of the Rails 4 streaming code.

I can't say exactly, except with this middleware loaded calls to otherwise streaming endpoints return with a Content-length header, and they return after one iteration of their runloop.

It must be the close that the middleware is doing on the Rack body object. I'll make some time to play around with the streaming API today and see if that's the case, but that's where my money is right now. Avoiding close when the Content-Type is text/event-stream I bet would fix the issue.

Almost certainly would @johnbintz, I wonder if the Rack body object looks different in Rails streaming from your POV. At least in ALL examples about how this might work they say it's ESSENTIAL to ensure\n\tresponse.stream.close, which makes your proposed fix safe enough.

I just rode the Rails 4 SSE wave successfully with rack-livereload running. Hopefully that commit should fix it. Let me know if it doesn't.